如何使ggPredict图中的数据点更透明?

huangapple go评论57阅读模式
英文:

How to make data points in ggPredict plot more transparent?

问题

这是我的代码:

fit4=lm(Response~r*delta*sw,data=ChemResearch4)
summary(fit4)
b<-ggPredict(fit4,colorn=10,add.data=FALSE)+
plot(b)+
  labs(
    x = "r",
    y = "Response",
    title = "Effect of delta and r on response, by sw values")

这是图表:

如何使ggPredict图中的数据点更透明?

谢谢!

我尝试过使用geom_point,但一直出现错误。

英文:

this is my code:

fit4=lm(Response~r*delta*sw,data=ChemResearch4)
    summary(fit4)
b&lt;-ggPredict(fit4,colorn=10,add.data=FALSE)+
plot(b)+
  labs(
    x = &quot;r&quot;,
    y = &quot;Response&quot;,
    title = &quot;Effect of delta and r on response, by sw values&quot;)

This is the plot:

如何使ggPredict图中的数据点更透明?

Thank you!

I tried geom_point, but it constantly shows error.

答案1

得分: 0

我看不到在 ggPredict 函数内部更改透明度的选项,但由于它生成了一个 ggplot 对象,您可以在绘制完成后将透明度作为美学参数添加到点图层中。

由于我们没有您的数据,所以这里是一个使用内置的 mtcars 数据集的完整 reprex:

library(ggiraphExtra)

fit4 <- lm(mpg ~ wt * hp, data = mtcars)

b <- ggPredict(fit4, colorn = 10, add.data = FALSE) 

plot(b)

如何使ggPredict图中的数据点更透明?

请注意,点是完全不透明的。要使它们半透明,我们可以执行以下操作:

b$layers[[1]]$aes_params <- list(alpha = 0.2)

plot(b)

如何使ggPredict图中的数据点更透明?

创建于2023年07月13日,使用 reprex v2.0.2

英文:

I don't see an option to change the transparency within the ggPredict function itself, but since it produces a ggplot object, you can add transparency as an aesthetic parameter to the point layer after the plot is produced.

We don't have your data, so here is a full reprex using the built-in mtcars data set:

library(ggiraphExtra)

fit4 &lt;- lm(mpg ~ wt * hp, data = mtcars)

b &lt;- ggPredict(fit4, colorn = 10, add.data = FALSE) 

plot(b)

如何使ggPredict图中的数据点更透明?

Note the points are fully opaque. To make them transparent, we can do:

b$layers[[1]]$aes_params &lt;- list(alpha = 0.2)

plot(b)

如何使ggPredict图中的数据点更透明?

<sup>Created on 2023-07-13 with reprex v2.0.2</sup>

huangapple
  • 本文由 发表于 2023年7月13日 23:39:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76681184.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定