首页 > 解决方案 > 合并几何线和点的图例

问题描述

我对 R Script 很陌生。如果你能帮助我的问题,那就太好了......这是我的问题......

我可以使用 R 脚本创建自定义视觉效果,并通过使用以下链接链接在该视觉效果上悬停我认为它也显示了线和点的图例。就是它在图表中向我展示的方式

在此处输入图像描述

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

在此处输入图像描述

请在下面找到 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');

标签: rggplot2plotly

解决方案


推荐阅读