Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8270637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:38:26+00:00 2026-06-08T06:38:26+00:00

Before explaining details, here is my data: set.seed (1234) datas <- data.frame (Indv =

  • 0

Before explaining details, here is my data:

set.seed (1234) 
datas <- data.frame (Indv = 1:20, Xvar = rnorm (20, 50, 10),
Yvar = rnorm (20, 30,5), Yvar1 = rnorm (20, 10, 2),
Yvar2 = rnorm (20, 5, 1), Yvar3 = rnorm (20, 100, 20),
Yvar4 = rnorm (20, 15, 3))

I want to prepare a graph (Metroglymph ) which is essentially point plot however points (of Xvar and Yvar) with spikes (lines) orignated from the point scaled to rest of variables (Yvar1, Yvar2, Yvar3, Yvar4).
Each spike are ordered and preferably color coded.

require(ggplot2)
ggplot(datas, aes(x=Xvar, y=Yvar)) +
    geom_point(shape=1, size = 10) + theme_bw()

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:38:28+00:00Added an answer on June 8, 2026 at 6:38 am

    Here is one possible approach that may be helpful to you. It uses stat_spoke() from ggplot2. Each of your y-variables is mapped to the spoke radius in 4 separate calls to stat_spoke.

    plot_1 = ggplot(datas, aes(x=Xvar, y=Yvar)) +
             stat_spoke(aes(angle=(1/8)*pi, radius=Yvar1), colour="#E41A1C",size=1) +
             stat_spoke(aes(angle=(3/8)*pi, radius=Yvar2), colour="#377EB8",size=1) +
             stat_spoke(aes(angle=(5/8)*pi, radius=Yvar3), colour="#4DAF4A",size=1) +
             stat_spoke(aes(angle=(7/8)*pi, radius=Yvar4), colour="#984EA3",size=1) +
             geom_point(shape=1, size = 10)
    
    ggsave("plot_1.png", plot_1)
    

    enter image description here

    Depending on your data and specific needs, it may make sense to transform the variables so they fit better on the plot.

    normalize = function(x) {
        new_x = (x - mean(x)) / sd(x)
        new_x = new_x + abs(min(new_x))
        return(new_x)
    }
    
    plot_2 = ggplot(datas, aes(x=Xvar, y=Yvar)) +
             stat_spoke(aes(angle=(1/8)*pi, radius=normalize(Yvar1)), colour="#E41A1C", size=1) +
             stat_spoke(aes(angle=(3/8)*pi, radius=normalize(Yvar2)), colour="#377EB8", size=1) +
             stat_spoke(aes(angle=(5/8)*pi, radius=normalize(Yvar3)), colour="#4DAF4A", size=1) +
             stat_spoke(aes(angle=(7/8)*pi, radius=normalize(Yvar4)), colour="#984EA3", size=1) +
             geom_point(shape=1, size = 10)
    
    ggsave("plot_2.png", plot_2)
    

    enter image description here

    Important caveat: For the same spoke radius value, the magnitude of the plotted line will be greater if the line is more vertical, and less if the line is more horizontal. This is because the range of x is around twice the range of y for your data set. The plotted angles also become distorted as the x-to-y axis ratio changes. Adding coord_equal(ratio=1) solves this issue, but may introduce other problems.
    enter image description here

    Edit: Plotting without a loop

    This was fun and educational to figure out. Possibly it would have been more time-efficient to type the repetitive code! If anyone can offer advice to improve this code, please comment.

    library(reshape2)
    
    dat2 = melt(datas, id.vars=c("Indv", "Xvar", "Yvar"), 
                variable.name="spoke_var", value.name="spoke_value")
    
    # Apply normalization in a loop. Can plyr do this more gracefully?.
    for (var_name in levels(dat2$spoke_var)) {
        select_rows = dat2$spoke_var == var_name
        norm_dat = normalize(dat2[select_rows, "spoke_value"])
        dat2[select_rows, "spoke_value"] = norm_dat
    }
    
    # Pick an angle for each Yvar, then add angle column to dat2.
    tmp = data.frame(spoke_var=unique(dat2$spoke_var))
    tmp$spoke_angle = seq(from=pi/8, by=pi/4, length.out=nrow(tmp))
    dat2 = merge(dat2, tmp)
    
    plot_4 = ggplot(dat2, aes(x=Xvar, y=Yvar)) +
             stat_spoke(data=dat2, size=1,
                        aes(colour=spoke_var, angle=spoke_angle, radius=spoke_value)) +
             geom_point(data=datas, aes(x=Xvar, y=Yvar), shape=1, size=7) +
             coord_equal(ratio=1) +
             scale_colour_brewer(palette="Set1")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before explaining the problem I am facing,this is the code I am using: <!DOCTYPE
This has some lengthy background before the actual question, however, it bears some explaining
I did a poor job of explaining my original question, so here's a second
Before I start explaining the code I will first give my use case so
I have been here before, asking for a mapping library that could store objects
I'll start with the background story before explaining the problem with my code. I'm
Good evening everyone, before explaining my problem, I should give you some explanation on
Well !!!!! I am here explaining about my app first. I have 3 UIViews
I have been trying to ask this before, without any luck of explaining/proving a
before I start I want to point out that I tagged this question as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.