gpt4 book ai didi

r - 当我在散点图中将轴的原点设置为零时,点被切断

转载 作者:行者123 更新时间:2023-12-05 09:15:29 25 4
gpt4 key购买 nike

当我将散点图上的 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 查看器中产生了这个

enter image description here

顶部和底部的点被切断。如何在不切断的情况下显示每个点?

最佳答案

您需要在坐标规范上使用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 创建于 2018-09-16 (v0.2.0).

关于r - 当我在散点图中将轴的原点设置为零时,点被切断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52359674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com