gpt4 book ai didi

r - 将 geom_pointrange 中点和线的大小与 ggplot 分开

转载 作者:行者123 更新时间:2023-12-03 23:13:08 24 4
gpt4 key购买 nike

使用 ggplotgeom_pointrange() 函数,如何分别改变点的大小和线的粗细?

例子:

# make test data
df <- data.frame(y=10, ymin=1, ymax=20, x=1)

# store ggplot object
p <- ggplot(data=df, aes(y=y, ymin=ymin, ymax=ymax, x=x))

# plot 1: big dot and thick line
p + geom_pointrange(fill='blue', color='grey', shape=21, size=5)

# plot 2: small dot and thin line (I want small dot and thick line or vice versa)
p + geom_pointrange(fill='blue', color='grey', shape=21, lwd=1, size=5)

情节 1:

enter image description here

情节 2:

enter image description here

我可以得到一个带有粗线的小点吗(反之亦然)?

解决方法可能是使用 geom_pointgeom_errorbar 将线和点绘制为单独的几何图形。不幸的是,我的实际应用涉及抖动,所以点和间隔最终在不同的地方(除非我可以控制抖动?)。

我可以在 SO ( like this ) 上找到类似的问题,但他们没有直接回答这个问题。

谢谢!

最佳答案

您可以将 fattensize 结合使用:

p + geom_pointrange(fill='blue', color='grey', shape=21, fatten = 20, size = 5)

enter image description here
p + geom_pointrange(fill='blue', color='grey', shape=21, fatten = .5, size = 5)

enter image description here

s。 ?geom_pointrange:

fatten
A multiplicative factor used to increase the size of the middle bar in geom_crossbar() and the middle point in geom_pointrange().

关于r - 将 geom_pointrange 中点和线的大小与 ggplot 分开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37576945/

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