[英]stacked bar plot in R
I suggest ggplot2 to get your barplot.我建议使用ggplot2来获取您的条形图。
Check out this How to Make a Stacked Bar Chart in R Using ggplot2 .查看如何使用 ggplot2 在 R 中制作堆积条形图。
Read the ggplot docs and have a try.阅读 ggplot 文档并尝试一下。
By the way ,it's good for you to read how to ask .顺便说一句,阅读如何提问对您有好处。
Hope this helps.希望这可以帮助。
I do not fully get how your table produces the plot you provide since both columns have equal values, and the plot has 9 vs 6 values.我不完全了解您的表格如何生成您提供的图,因为两列具有相等的值,并且该图有 9 对 6 值。
With R base you could try:使用 R 基础,您可以尝试:
df <- data.frame( A = c(1,1,2,1,3,4,4),
B = c(55,43,44,89,55,43,55))
df2 <- data.frame(cat = rep(c("A","B"),each=nrow(df)), val = c(df$A,df$B))
barplot(as.matrix(table(df2$val,df2$cat)))
You would need some additional work on the data to get the colors between A and B similar.您需要对数据进行一些额外的工作才能使 A 和 B 之间的颜色相似。 Since A and B have different types of values, the plot now has 6 different colors.
由于 A 和 B 具有不同类型的值,因此该图现在有 6 种不同的颜色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.