Discussion:
ggplot for a list?
bic ton
2018-06-12 17:03:52 UTC
Permalink
​ Hi,

My data looks like this:

I want to plot histogram (like the attached one) and I know it can be done
like this:

ggplot() + geom_histogram()



However, here I have a list and I am not sure how I do it. If I convert to
dataframe, I will los the order that I want to keep in the graph (1 and
3).



list(structure(list(Group.1 = structure(3:4, .Label = c("A",

"B", "C", "D", "E", "F"), class = "factor"), Pr1 = c(65, 75), Pr2 = c(54,
88), Prh = c(25, 5), SE = c(25, 75 )), row.names = c(NA, -2L), class =
"data.frame"),NULL, structure(list( Group.1 = structure(3:4, .Label =
c("A",

"B", "C", "D", "E", "F"), class = "factor"), Pr1 = c(81,4), Pr2 = c(66,
57),Prh = c(3,3), SE = c(8, 9)), row.names = c(NA,

-2L), class = "data.frame"))

Any help on this?

Thanks

Bick
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ***@googlegroups.com
To unsubscribe: email ggplot2+***@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Brandon Hurr
2018-06-12 18:30:45 UTC
Permalink
Bick,

When you import the data, can you create the missing groupings? Trying to
do it after the fact is really hard. Once you do that, it's super easy to
compact this with dplyr::bind_rows().
bic_data %>% dplyr::bind_rows()
Group.1 Pr1 Pr2 Prh SE
1 C 65 54 25 25
2 D 75 88 5 75
3 C 81 66 3 8
4 D 4 57 3 9

If you put a group variable in:
bic_data2 <- list(structure(list(super_group = c(1,1), Group.1 =
structure(3:4, .Label = c("A",

"B", "C", "D", "E", "F"), class = "factor"), Pr1 = c(65, 75), Pr2 = c(54,
88), Prh = c(25, 5), SE = c(25, 75 )), row.names = c(NA, -2L), class =
"data.frame"), NULL, structure(list(super_group = c(3,3), Group.1 =
structure(3:4, .Label = c("A",

"B", "C", "D", "E", "F"), class = "factor"), Pr1 = c(81,4), Pr2 = c(66,
57),Prh = c(3,3), SE = c(8, 9)), row.names = c(NA,

-2L), class = "data.frame"))

bic_data2 %>%
bind_rows() %>%
ggplot(., aes(x = Group.1, y = Pr1, fill = Group.1)) +
geom_bar(stat = "identity") +
facet_grid(. ~ super_group)
[image: Screen Shot 2018-06-12 at 11.30.11 AM.png]
HTH
B
​ Hi,
I want to plot histogram (like the attached one) and I know it can be done
ggplot() + geom_histogram()
However, here I have a list and I am not sure how I do it. If I convert to
dataframe, I will los the order that I want to keep in the graph (1 and
3).
list(structure(list(Group.1 = structure(3:4, .Label = c("A",
"B", "C", "D", "E", "F"), class = "factor"), Pr1 = c(65, 75), Pr2 = c(54,
88), Prh = c(25, 5), SE = c(25, 75 )), row.names = c(NA, -2L), class =
"data.frame"),NULL, structure(list( Group.1 = structure(3:4, .Label =
c("A",
"B", "C", "D", "E", "F"), class = "factor"), Pr1 = c(81,4), Pr2 = c(66,
57),Prh = c(3,3), SE = c(8, 9)), row.names = c(NA,
-2L), class = "data.frame"))
Any help on this?
Thanks
Bick
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
https://github.com/hadley/devtools/wiki/Reproducibility
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ***@googlegroups.com
To unsubscribe: email ggplot2+***@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...