meeeeeeeeo
话说关于对主Y轴和次Y轴坐标轴范围的变换,为撒不能改成下面这样呢?
coeff <- max(diamonds.new2$y2) / max(diamonds.new2$y1)
ggplot(data = diamonds.new2, aes(x = cut)) +
geom_bar(aes(y = y1), stat = 'identity', position = 'dodge') +
geom_line(aes(y = y2 * coeff), group = 1) +
scale_y_continuous(name = "主Y轴",
sec.axis = sec_axis( ~ . * coeff, name = "次Y轴"))
我以为在sec.axis = sec_axis( ~ . * coeff, name = "次Y轴")
这里面的这部分~ . * coeff
,这个.
是指主 Y 轴的范围,那么除以一个极小的数不就等于乘以一个很大的数吗?
俺找到原因了,如下是正常的。但是不明白为撒画图的时候要把次 Y 轴的数据先缩小到跟主 Y 轴一个范围,设置具体坐标轴范围时又重新放大?
coeff <- max(diamonds.new2$y2) / max(diamonds.new2$y1)
ggplot(data = diamonds.new2, aes(x = cut)) +
geom_bar(aes(y = y1), stat = 'identity', position = 'dodge') +
geom_line(aes(y = y2 / coeff), group = 1) +
scale_y_continuous(name = "主Y轴",
sec.axis = sec_axis( ~ . * coeff, name = "次Y轴"))