如何在R中生成3-D条形图? [英] How to generate 3-D bar graph in R?

查看:89
本文介绍了如何在R中生成3-D条形图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的data.frame,

This is my data.frame,

> head(dat)
  word value number         name
1   10 0.001     30 gi|378283288
2   15 0.001     17 gi|378283288
3   20 0.001     16 gi|378283288
4   25 0.001     14 gi|378283288
5   30 0.001     12 gi|378283288
6   10 0.010     38 gi|378283288

> tail(dat)
    word value number         name
120   30   0.5     27 gi|378285158
121   10   1.0     34 gi|378285158
122   15   1.0     31 gi|378285158
123   20   1.0     27 gi|378285158
124   25   1.0     27 gi|378285158
125   30   1.0     27 gi|378285158

我想以条形图展示它.我探讨了这些选项,但尚未成功,因为我想介绍所有四个专栏. value可以用作X-axisword可以用作y-axis,而name可以用作Z-axis.那么如何在这里使用number?
可能是这样的图形会有所帮助,我可以通过使用legend中的色标来表示number.
现在,我的问题是,如何在R中生成该图?这是显示我的数据的正确方法吗?

I want to present it in a bar graph. I explored the options, but not succeeded yet, because I want to present all the four columns. value can be used as X-axis, word can be used as y-axis and the name can be used as Z-axis. Then how to use number here?
May be a graph like this will be helpful, I can represent number by using color scale in legend.
Now, my question is, how to generate this plot in R? and is it a right way to present my data?

推荐答案

我会做这样的事情:

library(ggplot2)
theme_set(theme_bw())
theme_update(strip.background=element_rect(colour="white"))

cities <- c("Beijing", "Hong Kong", "Macau", "Nanjing")
measures <- sprintf("Particle %s", toupper(letters[1:8]))
df <- data.frame(expand.grid(city=cities, measure=measures))
df$value <- rexp(nrow(df))

p <- (ggplot(df, aes(x=measure, y=value, color=measure, group=city)) +
      scale_color_discrete(guide=FALSE) +
      geom_point() + facet_wrap(~ city) +
      geom_line(color="grey", alpha=0.5) +
      xlab(""))
p

...与注释中所建议的阴影没有什么不同.

...which isn't so different from what shadow suggested in the comments.

我正在回答您的最后一个问题(主观):"[3D条形图是一种很好的方式来显示我的数据."我更喜欢多面2D图而不是3D.

I'm giving my (subjective) answer to your last question, "is [a 3D barplot a good] way to present my data." I'd prefer a faceted 2D plot to something 3D.

这篇关于如何在R中生成3-D条形图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆