在诊断图(ggplot2)的情况下,可以更改平滑线的线宽? [英] It is possible to change line width for smoother lines in case of diagnostic plot (ggplot2)?

查看:861
本文介绍了在诊断图(ggplot2)的情况下,可以更改平滑线的线宽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在ggplot2中自定义诊断图。我试过这个:

  library(ggfortify)
library(ggplot2)
model1< - lm (len〜dose * supp,data = ToothGrowth)
autoplot(model1,which = 1,label.size = 3,data = ToothGrowth,size = 3,color =dose,
smooth.colour ='darkblue',smooth.linetype =dotted,smooth.linesize = 3)

这张图片:





我改变了线条颜色线条类型更流畅,但我不知道如何更改线条宽度。我尝试过smooth.linesize,但它不起作用。有可能以某种方式改变线宽?



有人可以帮助我吗? / code>不提供所需的参数 smooth.linesize 。第一部分生成你的情节, p

  p < autoplot(model1,which = 1,label.size = 3,data = ToothGrowth,size = 3,color =dose,
smooth.colour ='darkblue',smooth.linetype =dotted)

平滑线的所需数据现在可以在 p 这里: p @ plots [[1]] $ layers [[2]] $ data



在调用 geom _ * 时,这可以用作 data 参数。以下代码生成下面的图。

  p + geom_line(data = p @ plots [[1]] $ layers [[2]] $ data,aes( x = x,y = y),linetype = 3,col =red,size = 3)



另一个选择是添加尚未存在的美学参数 size 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]]$data

This 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 via

p@plots[[1]]$layers[[2]]$aes_params$size <- 3
p

I hope this helps.

这篇关于在诊断图(ggplot2)的情况下,可以更改平滑线的线宽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆