R,ggplot;在ggplot中的图例中独立控制符号的大小和线宽

当基于mpg数据集时,我有一个基本上看起来像这样的情节:

library(datasets)    
plot2 <- ggplot(mapping = aes(
      x = cty,y = hwy,group = as.factor(cyl),shape = as.factor(cyl),linetype = as.factor(cyl)),data = mpg) +
      geom_point() +
      geom_smooth(method = lm,se = F,color = "black") +
      theme(legend.key.width = unit(4,"cm"))
plot2

我希望能够在不影响线条粗细的情况下控制图例中符号的大小。尝试在类似的线程中使用override.aes的想法会产生较大的符号,但同时会增加粗线。

plot2 + guides(shape = guide_legend(override.aes = list(size=5)))

Modifying legends in ggplot2 with interactions and guides部分描述了该问题;但是,链接中的问题将地址更改为Geom_Path而不是Geom_Smooth,并且没有解释如何找到要更改的ggproto()对象的确切定义。如果有人可以提供此信息会很有帮助-然后我可能自己以类似方式修改代码。

jideyouwo 回答:R,ggplot;在ggplot中的图例中独立控制符号的大小和线宽

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3085665.html

大家都在问