geom_crossbar产生一个不适当的y尺度的情节 [英] geom_crossbar produces a plot with inappropriate y scale

查看:494
本文介绍了geom_crossbar产生一个不适当的y尺度的情节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果不附上剧情图片,很难描述我的问题。我有两组数据,其中一组有两个观察值,平均值约为1,误差约为1.5;另一个有两个观察值,平均值在30左右,误差在2左右。



但是在图中,柱线重叠,y轴刻度标记失序: p>

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 < - 结构(列表(factor1 =结构(c(1L,1L,2L,2L),。标签= c(oil1,oil2),class =factor),因子2 =结构c(1L,2L,1L,2L),.Label = c(prod1,prod2),class =factor),value = c(1.7,1,29.8,31.3),err = c ,1,2,2),min = c(0.2,0,27.8,29.3),max = c(3.2,2,31.8,33.3)),.Name = c(factor1,factor2,value (1,2,3,4))

#图
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

我会大大提供帮助,现在我已经坚持了两天。

解决方案

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


It is difficult to describe my problem without attaching an image of the plot. I have two groups of data, one with two observations having mean around 1 and error around 1.5; the other has two observations with mean around 30 and error around 2.

But in the plot the bars overlap and the y-axis tick marks are out of order:

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

Data and code (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

I would greatly apreciate help on this, I have been stuck on it for two days now. Thanks in advance.

解决方案

Using your data and your script I get:

这篇关于geom_crossbar产生一个不适当的y尺度的情节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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