我正在构建一个显示介于 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, 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)
)
Run Code Online (Sandbox Code Playgroud)
适用于情节周围边距的解决方案:
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"))
Run Code Online (Sandbox Code Playgroud)