【问题标题】:geom_crossbar produces a plot with inappropriate y scalegeom_crossbar 生成一个 y 比例尺不合适的图
【发布时间】:2015-02-04 07:16:05
【问题描述】:

如果不附上情节图像,很难描述我的问题。我有两组数据,一组有两个观察值,平均值约为 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

我会非常感谢您的帮助,我已经坚持了两天了。提前致谢。

【问题讨论】:

  • 我没有看到使用您的数据和脚本的重叠。
  • 我正在使用 RStudio 版本。 0.98.1062; R版。 3.0.3 (2014-03-06) 和 ggplot2 版本。 1.0.0,如果有帮助的话。
  • RStudio 与此无关。我使用了相同版本的ggplot2。
  • 我也尝试将绘图直接保存为 .png 文件,但同样的事情发生了。帕斯卡,您能否在此处使用我的数据和脚本发布您的结果图像?

标签: r ggplot2


【解决方案1】:

使用您的数据和脚本,我得到:

【讨论】:

  • 这是我想要的,但我无法得到它。我现在更难过了。
  • 现在我让它工作了,但它仍然很奇怪。使用您提供的代码my.data &lt;- 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")),结果显示正常。但如果数据框是使用 read.table 从 .csv 创建的,则不是。
  • 你需要检查read.table的输出,特别是列的类,即数字是否真的是数字。 read.table 中有一个选项可以避免此类问题。
  • 谢谢,我会调查这个问题
  • 问题是将数据帧的子集转换为数字,正如另一个问题所示:stackoverflow.com/questions/12868122/…,对吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-26
  • 1970-01-01
  • 2019-06-12
  • 1970-01-01
相关资源
最近更新 更多