可以更改平滑线的线宽

可以更改平滑线的线宽

本文介绍了在诊断图(ggplot2)的情况下,可以更改平滑线的线宽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想在ggplot2中自定义诊断图。我试过这个: / code>不提供所需的参数 code>到你自己的阴谋对象的相应层。我猜这个选项更接近你要达到的目标。 这可以通过 p @ plots [[1]] $ layers [[2]] $ aes_params $ size< - 3 p 我希望这有助于。 I would like to customise diagnostic plots in ggplot2. I have tried this:library(ggfortify)library(ggplot2)model1 <- lm(len~dose*supp, data = ToothGrowth)autoplot(model1, which = 1, label.size = 3, data = ToothGrowth, size=3, colour = "dose", smooth.colour = 'darkblue', smooth.linetype="dotted", smooth.linesize=3)I got this picture:I changed the line colour and line type for smoother line, but I do not know how can I change the line width. I have tried "smooth.linesize", but it is not working. It is possible somehow change the line width?Can somebody help me? Thank You. 解决方案 One option would be to add another layer to your plot since autoplot.lm does not provide the desired argument smooth.linesize. The first part generates your plot, p.p <- autoplot(model1, which = 1, label.size = 3, data = ToothGrowth, size=3, colour = "dose", smooth.colour = 'darkblue', smooth.linetype="dotted")The desired data of the smoothed line can now be found somewhere deep inside p here: p@plots[[1]]$layers[[2]]$dataThis can be used as the data argument in the call to geom_*. The following code generates the plot below. p + geom_line(data = p@plots[[1]]$layers[[2]]$data, aes(x = x, y = y), linetype = 3, col = "red", size = 3)Another option would be to add the not yet existing aesthetics parameter size to the respective layer of the plot object yourself. I guess this option is closer to what you want to achieve.This can be done viap@plots[[1]]$layers[[2]]$aes_params$size <- 3pI hope this helps. 这篇关于在诊断图(ggplot2)的情况下,可以更改平滑线的线宽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 20:32