【问题标题】:boxplot the data on y-azis of scatter plot using R or ggplot2使用 R 或 ggplot2 在散点图的 y 轴上绘制数据
【发布时间】:2016-08-09 15:40:15
【问题描述】:

boxplot the data of the y-axis of a scatter plot using matlab

我想像上面的问题一样创建图:使用 y 轴作为箱形图的定量比例,而 x 轴是另一个定量值。我如何在 R 中执行此操作,或者最好在 ggplot2 中执行此操作?

【问题讨论】:

  • 一个可重复的例子可能会有所帮助:stackoverflow.com/questions/5963269/…
  • 你试过什么? with(mtcars, qplot(x = cyl, y = hp, group = cyl, geom = 'boxplot')) 似乎工作得很好

标签: r ggplot2 scatter-plot boxplot


【解决方案1】:

假设离散值将group 添加到变量中:

set.seed(123)
dat <- data.frame(col1=rexp(10), col2=rep(1:2, each=5))
ggplot(dat, aes(y=col1, x=col2, group=col2)) + geom_boxplot()

如果没有,那就自己做一个:D

dat <- data.frame(col1=rexp(100), col2=rexp(100))
nxbins <- 3
dat$col3 <- cut(dat$col2, nxbins)
levels(dat$col3) <- with(dat, tapply(col2, col3, mean))
dat$col3 <- as.numeric(as.character(dat$col3))
ggplot(dat, aes(y=col1, x=col3, group=col3)) + geom_boxplot()

附: 当然,最好由你准备一个可重现的例子,而不是我可耻的猜测......

【讨论】:

  • 感谢您回答我的愚蠢问题,这似乎是我需要的。
  • 谢谢你让我有机会感到有用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-04
  • 1970-01-01
相关资源
最近更新 更多