当我在散点图中将X轴和Y轴原点设置为0时,图表边缘上的点将被切除。
ggplot(
data = cars,
aes(
x = speed,
y = dist
)
) +
geom_point(
size = 3
) +
scale_x_continuous(
breaks = seq(
from = 0,
to = max(cars$speed),
by = 5
)
) +
scale_y_continuous(
breaks = seq(
from = 0,
to = max(cars$dist),
by = 5
),
expand = c(0,0)
)
上面的代码是在RStudio查看器中产生的
顶部和底部的点被切断。如何显示每个点而不将其切断?
答案 0 :(得分:3)
您需要在坐标规范上使用clip = "off"
。
library(ggplot2)
ggplot(
data = cars,
aes(
x = speed,
y = dist
)
) +
geom_point(
size = 3
) +
scale_x_continuous(
breaks = seq(
from = 0,
to = max(cars$speed),
by = 5
)
) +
scale_y_continuous(
breaks = seq(
from = 0,
to = max(cars$dist),
by = 5
),
expand = c(0,0)
) +
coord_cartesian(clip = "off")
由reprex package(v0.2.0)于2018-09-16创建。