2017-05-15 151 views
0

我有一个简单的ggplot,我需要合并一个对数刻度y轴英寸的麻烦。我明白,ggplot是正确的弯曲线一旦我的轴有对数刻度,但我需要线仍然线性连接我的数据点。ggplot对数刻度y轴直线

这是我的代码:

forexample<-transform(example, EXP=factor(EXP, levels=unique(EXP))) 
plot<-ggplot(forexample, aes(x=EXP, y=concentration, shape=sample)) 
+ stat_summary(aes(group = sample), fun.y = mean, geom = 'line', alpha=1, size=0.5) 
+ stat_summary(aes(group = sample), fun.y = mean, geom = 'point', alpha=1, size=4) + 
theme_bw() + 
coord_trans(y = "log10") 

我的数据结构是这样的:

sample concentration EXP 
H  0.08   Ex1 
H  0.07   Ex2 
M  2.00   Ex1 
M  0.50   Ex2 
R  0.01   Ex1 

...

我试图Zoltáns建议在这个问题:“GGPLOT2登录Y的规模轴导致曲线“,但它没有为我工作。 (ggplot2 log scale of y axis causing curved lines

如果有人能帮助我,我真的很高兴! 谢谢:)

enter image description here

回答

2

这是coord_trans预期的行为,是从scale_y_log10不同。另请参见:https://stackoverflow.com/a/25257463/3330437

require(dplyr) # for data construction 
require(scales) # for modifying the y-axis 

data_frame(x = rep(letters, 3), 
      y = rexp(26*3), 
      sample = rep(c("H", "M", "R"), each = 26)) %>% 
    ggplot(aes(x, y, shape = sample)) + theme_bw() + 
    geom_point() + geom_path(aes(group = sample)) + 
    scale_y_log10() 

enter image description here

如果你想y轴标签和网格线看起来更像coord_trans默认设置,使用scale_y_log10(breaks = scales::pretty_breaks())

enter image description here

+0

非常感谢你:) – Pauline