I was smoothing the line of my graph with "geom_xspline", it works quite well, but the problem is that you can't adjust the width of the line. I want the widest line

附件为数据:

AÑO <- seq(2005,2024, by = 1)
PIA_increase <- c(-30501,24337, -23296,12718,314,  14499,  86065, -54206,66258,  20795,  20901, 107653,
                          -8149 , 91357 ,  152 ,-58815  , 0, 229997,    378 ,204403
                          ) 
Congreso_1 <- data.frame(AÑO, PIA_increase)

library(ggalt)

ggplot(Congreso_1, aes(AÑO,PIA_increase))+
  geom_point(color = "red")+
  geom_xspline(position = "identity",spline_shape=-0.4, color = "red", size = 1)+ aes(lwd = 2)+
  theme(panel.background = element_rect(fill = "white"))

我try 添加"aes(lwd = 2)"功能,但线条变得太粗,无法调整.

enter image description here

我希望能够在1到1.5之间调整线

推荐答案

主要的问题是,ggalt不能解释ggplot2 3.4.0引入的linewidth美学.同样的问题已经在GH上提交了.

使用+ aes(lwd = 2)是"修复"问题的变通办法,但您还必须使用scale_linewidth_identity设置linewidth的比例.否则,将应用线条宽度的默认比例.

library(ggalt)

ggplot(Congreso_1, aes(AÑO, PIA_increase)) +
  geom_point(color = "red") +
  geom_xspline(
    position = "identity", 
    spline_shape = -0.4,
    color = "blue"
  ) +
  aes(lwd = 2) +
  scale_linewidth_identity() +
  theme(panel.background = element_rect(fill = "white"))
#> Warning: Using the `size` aesthetic in this geom was deprecated in ggplot2 3.4.0.
#> ℹ Please use `linewidth` in the `default_aes` field and elsewhere instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.

作为参考,这里是应用了默认比例的绘图:

ggplot(Congreso_1, aes(AÑO, PIA_increase)) +
  geom_point(color = "red") +
  geom_xspline(
    position = "identity", 
    spline_shape = -0.4,
    color = "blue"
  ) +
  aes(lwd = 2) +
  theme(panel.background = element_rect(fill = "white"))

R相关问答推荐

如何在ggplot 2 geom_segment图表中将UTC转换为EET?

更改网格的crs以匹配简单要素点对象的crs

将Multilinetring合并到一个线串中,使用sf生成规则间隔的点

使用R中的Shapetime裁剪格栅文件

以R中的正确顺序将日期时间字符列转换为posixct

修改用R编写的用户定义函数

然后根据不同的列值有条件地执行函数

我如何才能找到FAMILY=POISSON(LINK=&Q;LOG&Q;)中的模型预测指定值的日期?

在不丢失空值的情况下取消列出嵌套列表

用两种 colored颜色 填充方框图

更新R中的数据表(使用data.table)

为什么在BASE R中绘制线条时会看到线上的点?

在使用具有Bray-Curtis相似性的pvCluust时计算p值

有没有办法一次粘贴所有列

按组内中位数分类

无法将条件case_when()应用于使用!!创建的新变量Mutations

在r中整理图例和堆叠图的问题

如何修改GT表中组名行的 colored颜色 ?

如何将字符类对象中的数据转换为R中的字符串

真实世界坐标的逆st_变换