gpt4 book ai didi

r - 如何在 ggplot2 中为 x 轴添加特定值?

转载 作者:行者123 更新时间:2023-12-05 02:17:26 25 4
gpt4 key购买 nike

我正在尝试在 ggplot2 中制作图表。我希望 x 轴显示 2.84 以及下面键入的序列。除了在 breaks() 中输入所有精确值之外,还有其他方法吗?我试过谷歌,但它没有解决我的问题。

scale_x_continuous(limits = c(1, 7), seq(1,7,by=0.5), name = "Number of 
treatments")

最佳答案

您可以通过编程方式生成特定的中断,如下所示:

# make up some data
d <- data.frame(x = 6*runif(10) + 1,
y = runif(10))

# generate break positions
breaks = c(seq(1, 7, by=0.5), 2.84)
# and labels
labels = as.character(breaks)

# plot
ggplot(d, aes(x, y)) + geom_point() + theme_minimal() +
scale_x_continuous(limits = c(1, 7), breaks = breaks, labels = labels,
name = "Number of treatments")

enter image description here

关于r - 如何在 ggplot2 中为 x 轴添加特定值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47929869/

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