修改ggplot中y轴的值
modify the values in the y-axis in ggplot
我有一个 data.frame,其中我收集的数据是秒,我将其绘制在 y 轴上。但是,当我想绘制该数据时,我希望它以毫秒为单位绘制在 y 轴上。
如何修改 y 轴上出现的值,使它们比实际出现的数据大 1000 倍,同时标绘点保持不变?
这是我目前使用的代码:
ggplot(DSRCdelay_cl, aes(x=numVehicles, y=value, colour=as.factor(clusteringDistance) ) ) +
geom_smooth(fill=NA, aes(group=clusteringDistance, size=0 ) ) +
xlab(expression( "Vehicles (per" ~km^2~")" ) ) +
ylab("DSRC delay") + scale_y_continuous() +
expand_limits(x =c(0), y =c(0,0.1) )
与此问题密切相关的其他答案是:
transforming axis labels with a multiplier ggplot2 and: ggplot2 axis transformation by constant factor
轴文本和标签大小可以在函数 theme() 中使用 axis.text= 和 axis.title= 更改。要仅更改 y 轴标题大小,请指定 axis.title.y= 如下所示:
g+主题(axis.text=element_text(size=12),
axis.title.y=element_text(size=14,face="bold"))
以下是格式化 ggplot 图表的好参考:
使用函数乘以 y-axis
的标签值:
p + scale_y_continuous( labels=function(x)x*1000 )
我有一个 data.frame,其中我收集的数据是秒,我将其绘制在 y 轴上。但是,当我想绘制该数据时,我希望它以毫秒为单位绘制在 y 轴上。
如何修改 y 轴上出现的值,使它们比实际出现的数据大 1000 倍,同时标绘点保持不变?
这是我目前使用的代码:
ggplot(DSRCdelay_cl, aes(x=numVehicles, y=value, colour=as.factor(clusteringDistance) ) ) +
geom_smooth(fill=NA, aes(group=clusteringDistance, size=0 ) ) +
xlab(expression( "Vehicles (per" ~km^2~")" ) ) +
ylab("DSRC delay") + scale_y_continuous() +
expand_limits(x =c(0), y =c(0,0.1) )
与此问题密切相关的其他答案是: transforming axis labels with a multiplier ggplot2 and: ggplot2 axis transformation by constant factor
轴文本和标签大小可以在函数 theme() 中使用 axis.text= 和 axis.title= 更改。要仅更改 y 轴标题大小,请指定 axis.title.y= 如下所示:
g+主题(axis.text=element_text(size=12),
axis.title.y=element_text(size=14,face="bold"))
以下是格式化 ggplot 图表的好参考:
使用函数乘以 y-axis
的标签值:
p + scale_y_continuous( labels=function(x)x*1000 )