合并Geom Line和Point的图例

时间:2018-06-20 01:58:13

标签: r ggplot2 plotly

我对R Script很陌生。如果您能够解决我的问题,那真是太棒了...这是我的问题...

我可以使用R Script创建自定义视觉效果,并通过使用以下链接Link将鼠标悬停在该视觉效果上,我认为它也同时显示了线和点的图例。这就是它在图表Both Legends

中向我显示的方式

enter image description here

但是我想展示这样的东西……。表示同一图例名称Same legend中的线和点。

enter image description here

请在下面找到R脚本,请仔细阅读,您能告诉我我哪里出问题了...。

      source('./r_files/flatten_HTML.r')

图书馆声明

      library(htmlwidgets);library(XML);library(ggplot2);library(plotly);

      Values$Storiesgrouping <- as.character(Values$Storiesgrouping)
      Cols <- as.character(Values$Color)
      names(Cols) <- as.character(Values$Builder_CommunityName)
      Sizs <- as.numeric(Values$Size)
      names(Sizs) <- as.character(Values$Builder_CommunityName)

实际代码

g <- ggplot(Values, aes(x=BaseSquareFeet, y=BasePriceM, 
                        group=Builder_CommunityName, color=Builder_CommunityName))+
  geom_line()+
  geom_point(aes(shape=Storiesgrouping), show.legend=FALSE,size=3)+ 
  scale_colour_manual(values = Cols)+
  scale_size_manual(values = Sizs)+
  scale_shape_manual(values=c("1"=19, "2"=15, "3+"=17)) 
plot(g)

创建并保存小部件

p = ggplotly(g); internalSaveWidget(p, 'out.html');

0 个答案:

没有答案