[英]How do I adjust the decimal places of a ggplot axis label?
I made this plot with the following code:我用以下代码制作了这个图:
A %>%
drop_na(Roadgroup) %>%
drop_na(L.Share) %>%
filter(L.Share != "#DIV/0!") %>%
ggplot(aes(x=LP.share, y=L.Share, colour=Ward)) +
geom_point()
How would I go about making the y axis labels match the format of the x axis?我将如何使 y 轴标签与 x 轴的格式相匹配? (with both 2 decimal places, and less densely cluttered)
(两个小数位,并且不那么密集)
You can specify this with a function inside scale_y_continuous
with the breaks
argument:您可以使用
scale_y_continuous
的函数来指定它,并使用breaks
参数:
A %>%
drop_na(Roadgroup) %>%
drop_na(L.Share) %>%
filter(L.Share != "#DIV/0!") %>%
ggplot(aes(x=LP.share, y=L.Share, colour=Ward)) +
geom_point() +
scale_y_continuous(breaks = function(y) seq(floor(min(y, digits = 1)),
ceiling(max(y, digits = 1)),
by = 0.05))
You may need to modify my function(y)
here to fit your needs (by changing digits
, and by
).您可能需要在此处修改我的
function(y)
以满足您的需要(通过更改digits
和by
)。 However, if A$L.Share
is a factor, you will need to convert this to a numeric in order for scale_y_continuous
to work properly.但是,如果
A$L.Share
是一个因素,您需要将其转换为数字,以便scale_y_continuous
正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.