geom_crossbar生成一个y尺度不合适的图

时间:2015-02-04 07:16:05

标签: r ggplot2

如果不附加情节图像,很难描述我的问题。我有两组数据,一组有两个观察值,平均值约为1,误差约为1.5;另一个有两个观察值,平均值约为30,误差约为2。

但是在图中,条形重叠,y轴刻度标记乱序:

0; 0.1; 1; 1.7; 2; 27.8; 29.3; 29.8; 3.2; 31.3; 31.8; 33.3

数据和代码(dataframe my.data):

my.data <- structure(list(factor1 = structure(c(1L, 1L, 2L, 2L), .Label = c("oil1", "oil2"), class = "factor"), factor2 = structure(c(1L, 2L, 1L, 2L), .Label = c("prod1", "prod2"), class = "factor"), value = c(1.7, 1, 29.8, 31.3), err = c(1.5, 1, 2, 2), min = c(0.2, 0, 27.8, 29.3), max = c(3.2, 2, 31.8, 33.3)), .Names = c("factor1", "factor2", "value", "err", "min", "max"), class = "data.frame", row.names = c("1", "2", "3", "4"))

    # Plots
      p1 <- ggplot(data=my.data, aes(x=factor2, fill=factor1))
      p2 <- p1 + geom_crossbar(aes(y=value, ymin=min, ymax=max), position = position_dodge(width = 0.66), width=0.6)
      p2

我会非常赞赏这方面的帮助,我已经坚持了两天了。提前谢谢。

1 个答案:

答案 0 :(得分:0)

使用您的数据和脚本我得到: enter image description here