r语言报错:Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0. Please use `linewidth` instead.Error in `geom_col()`:
时间: 2023-11-21 12:54:14 浏览: 2098
这个报错信息包含两个部分:
1. `Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0. Please use `linewidth` instead`: 这是一个警告信息,意思是在ggplot2版本3.4.0中,使用`size`参数来控制线条宽度已经被弃用了,建议使用`linewidth`参数来代替。
2. `Error in `geom_col()`: 这是一个错误信息,意思是在使用`geom_col()`函数时出现了错误。
针对这个问题,有两种解决方法:
1. 使用`linewidth`参数代替`size`参数来控制线条宽度。例如,将原来的语句`geom_line(aes(x = col1, y = col2, size = col3))`改为`geom_line(aes(x = col1, y = col2, linewidth = col3))`。
2. 如果使用`geom_col()`函数时出现错误,需要检查语句中的参数是否正确,例如是否缺少`x`或`y`参数,或者`aes`语句是否正确。
相关问题
ggplot(data, aes(x=quarter, y=value, group=1)) + + geom_line(aes(y=Actual, color="Actual"), size=1.2) + + geom_line(aes(y=Pred, color="Predicted"), size=1.2) + + scale_x_yearqtr(n=8) + + xlab("Quarter") + + ylab("Stock Price") + + ggtitle("Actual vs. Predicted Stock Prices") + + theme(plot.title = element_text(hjust = 0.5)) Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0. Please use `linewidth` instead.
这个警告是因为在 `geom_line` 函数中使用了 `size` 参数来设置线条粗细,而这个参数在 ggplot2 3.4.0 版本后被弃用了,建议使用 `linewidth` 参数来代替。
所以,你可以将原来的代码中的 `size` 参数改为 `linewidth`,如下所示:
```
ggplot(data, aes(x=quarter, y=value, group=1)) +
geom_line(aes(y=Actual, color="Actual"), linewidth=1.2) +
geom_line(aes(y=Pred, color="Predicted"), linewidth=1.2) +
scale_x_yearqtr(n=8) +
xlab("Quarter") +
ylab("Stock Price") +
ggtitle("Actual vs. Predicted Stock Prices") +
theme(plot.title = element_text(hjust = 0.5))
```
这样就不会再出现警告了。
> ggplot()+ + geom_histogram(binwidth = 200,data=data,aes(x=SII,y=..frequency..),alpha = 0.8,colour="gold3",fill="gold3")+ + scale_y_continuous(sec.axis = sec_axis(~.*4000, name = "HR (95%CI) for 2-year all-cause mortality"))+ + geom_line(data=HR, aes(SII,yhat/4000), + linetype="solid",size=1,alpha = 0.7,colour="steelblue1")+ + geom_ribbon(data=HR, + aes(SII,ymin = lower/4000, ymax = upper/4000), + alpha = 0.1,fill="blue")+ + theme_classic()+ + geom_hline(yintercept=1/4000, linetype=2,size=1)+ + geom_vline(xintercept=570,size=1,linetype=2,color = '#d40e8c')+ + geom_vline(xintercept=1000,size=1,linetype=2,color = '#d40e8c')+#查表HR=1对应的age + labs(x="Systemic immune-inflammation index", y="Density")+ + xlim(0,4000)+ + labs(title = " ")+ + theme(plot.title = element_text(hjust = 0.5)) Error in `geom_histogram()`: ! Problem while mapping stat to aesthetics. ℹ Error occurred in the 1st layer. Caused by error in `map_statistic()`: ! Aesthetics must be valid computed stats. ✖ The following aesthetics are invalid: ✖ `y = ..frequency..` ℹ Did you map your stat in the wrong layer? Run `rlang::last_error()` to see where the error occurred. Warning messages: 1: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0. ℹ Please use `linewidth` instead. This warning is displayed once every 8 hours. Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated. 2: The dot-dot notation (`..frequency..`) was deprecated in ggplot2 3.4.0. ℹ Please use `after_stat(frequency)` instead. This warning is displayed once every 8 hours. Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated. 3: Removed 70 rows containing non-finite values (`stat_bin()`).
这段代码中出现了一些错误,其中一个是出现了无效的映射。具体而言,`y = ..frequency..` 这个映射是无效的,应该使用 `y = after_stat(frequency)`。另外,也出现了一些警告信息,例如 `size` 映射被弃用了,应该使用 `linewidth`。还有一个警告是有70个行包含了非有限值(`stat_bin()`)。这些问题需要修改才能正常运行代码。
阅读全文