Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 使用对数刻度时,如何在ggplot2中设置轴范围?_R_Ggplot2 - Fatal编程技术网

R 使用对数刻度时,如何在ggplot2中设置轴范围?

R 使用对数刻度时,如何在ggplot2中设置轴范围?,r,ggplot2,R,Ggplot2,我有一个时间序列数据,其中测量值都是1e6和1e8之间的整数:每个月的网站点击率。我想使用ggplot2绘制这些点和线,但将测量值映射到对数比例。大概是这样的: qplot(month, hits, data=hits.per.month, log="y") 当我这样做时,ggplot似乎将比例从1e6设置为1e8。我希望它从0扩展到1e8。这样做的自然方式似乎对输出没有影响: qplot(month, hits, data=hits.per.month, log="y", ylim=c(0,

我有一个时间序列数据,其中测量值都是1e6和1e8之间的整数:每个月的网站点击率。我想使用ggplot2绘制这些点和线,但将测量值映射到对数比例。大概是这样的:

qplot(month, hits, data=hits.per.month, log="y")
当我这样做时,ggplot似乎将比例从1e6设置为1e8。我希望它从0扩展到1e8。这样做的自然方式似乎对输出没有影响:

qplot(month, hits, data=hits.per.month, log="y", ylim=c(0, 100000000))
我可以通过在点击到达qplot之前转换点击来获得想要的图片,但这会改变轴上的标签:

qplot(month, log10(hits), data=hits.per.month, log="y", ylim=c(0, 8))
我还尝试了各种组合,使用
scale\u y\u log10
,但没有成功


那么,在ggplot2中使用对数刻度时,如何设置Y轴范围呢?

如果不使用
qplot
,我会更清楚地看到大部分ggplot2。这样,您就不会将所有内容都塞进一个函数调用中:

df <- data.frame(x = 1:10,
                 y = seq(1e6,1e8,length.out = 10))

ggplot(data = df,aes(x = x, y =y)) + 
    geom_point() + 
    scale_y_log10(limits = c(1,1e8))

df谢谢。这对我很有用。尽管我希望我能理解为什么这样做有效,而
qplot
版本却没有。你是如何让y轴上的值用上标表示的?我如何在y轴上的每个数字之间添加破折号以提高可见性(在ggplot中)?