R 如何避免expand=c(0,0)裁剪离轴刻度标签
我正在构建一个克利夫兰点图,显示0.0和1.0之间的值 我很快就能得到我想要的情节了,但一个微小的细节却困扰着我。因为我使用expand=c(0,0),所以x轴上1.00中的最后一个0被切断 我尝试过改变各种设置,但运气不好 不幸的是,这篇与这篇文章标题相似的文章没有帮助 你能帮我在不切断x轴上1.00的最后一个零的情况下保持绘图的边界吗 雷普雷克斯:R 如何避免expand=c(0,0)裁剪离轴刻度标签,r,ggplot2,R,Ggplot2,我正在构建一个克利夫兰点图,显示0.0和1.0之间的值 我很快就能得到我想要的情节了,但一个微小的细节却困扰着我。因为我使用expand=c(0,0),所以x轴上1.00中的最后一个0被切断 我尝试过改变各种设置,但运气不好 不幸的是,这篇与这篇文章标题相似的文章没有帮助 你能帮我在不切断x轴上1.00的最后一个零的情况下保持绘图的边界吗 雷普雷克斯: library(tidyverse) df <- tibble( Tastyness = c(0.6, 0.7, 0.9, 0.95
library(tidyverse)
df <- tibble(
Tastyness = c(0.6, 0.7, 0.9, 0.95, 0.98),
Fruit = c("Bananas", "Apples", "Oranges", "Mango", "Peach")
)
ggplot(df, aes(x = Tastyness, y = Fruit)) +
geom_point(size = 4) +
theme_bw() +
scale_x_continuous(
limits = c(0.0, 1.0),
expand = c(0, 0),
breaks = c(0, 0.5, 0.75, 0.9, 1.00)
)
库(tidyverse)
df可能会更改标签,以便0和1上没有小数:
ggplot(df, aes(x = Tastyness, y = Fruit)) +
geom_point(size = 4) +
theme_bw() +
scale_x_continuous(
limits = c(0.0, 1),
expand = c(0, 0),
breaks = c(0, 0.5, 0.75, 0.9, 1.00),
labels = c(0, 0.5, 0.75, 0.9, 1))
或水平移动标签:
ggplot(df, aes(x = Tastyness, y = Fruit)) +
geom_point(size = 4) +
theme_bw() +
scale_x_continuous(
limits = c(0.0, 1),
expand = c(0, 0),
breaks = c(0, 0.5, 0.75, 0.9, 1.00)) +
theme(axis.text.x = element_text(hjust = 1))
在绘图周围的边距上工作的解决方案:
ggplot(df, aes(x = Tastyness, y = Fruit)) +
geom_point(size = 4) +
theme_bw() +
scale_x_continuous(
limits = c(0.0, 1.0),
expand = c(0, 0),
breaks = c(0, 0.5, 0.75, 0.9, 1.00)
) +
theme(plot.margin=unit(c(.2,.5,.2,.2),"cm"))