-1

I am attempting to make the image shown here:

here

Using R code. Is there something better than dot plot for this type of figure? Basically I want to show the means and variability between two groups for 6 variables. Sample data provided below. Thanks a million!

 id var1 var2 var3  var4 group
 1  12    3    22   60    1
 2  8     6    19   55    1
 3  25    30   70   26    2
 4  26    31   75   31    2
 5  22    29   80   29    2
bvowe
  • 2,476
  • 1
  • 13
  • 20

1 Answers1

2

For what it's worth, the down-votes are a bit harsh IMO, but I think you could've improved the quality of your question by adding what you've tried so far. The SO community is usually very quick and eager to help, provided you demonstrate that you've done some work before. I didn't down-vote your question but the down-votes you've accrued are most likely due to the lack of attempt from your side. For future questions you should take a look at how to ask questions, and what you can do to provide a minimal reproducible example/attempt.

That aside, here is an example that should get you started

library(tidyverse)
df %>%
    gather(variable, v, -id, -group) %>%
    group_by(group, variable) %>%
    summarise(value = mean(v), value.sd = sd(v)) %>%
    ungroup() %>%
    mutate(
        variable = as.factor(variable),
        group = as.factor(group)) %>%
    ggplot(aes(x = value, y = variable, shape = group)) +
        geom_point(size = 4) +
        geom_segment(aes(x = value - value.sd, xend = value + value.sd, yend = variable))

enter image description here


Sample data

df <- read.table(text =
    "id var1 var2 var3  var4 group
 1  12    3    22   60    1
 2  8     6    19   55    1
 3  25    30   70   26    2
 4  26    31   75   31    2
 5  22    29   80   29    2", header = T)
Maurits Evers
  • 45,165
  • 4
  • 35
  • 59