Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:图例未显示在地图中_R_Ggplot2_Spatial_Ggplotly - Fatal编程技术网

R:图例未显示在地图中

R:图例未显示在地图中,r,ggplot2,spatial,ggplotly,R,Ggplot2,Spatial,Ggplotly,我制作了一张带有ggplot的地图,它根据我的数据框中的Freq值在地图上显示不同大小的点: Longitude Latitude Result Freq 4.690000 51.97400 Neg 1 6.040604 51.66494 Neg 23 6.87448 52.31593 Neg 4 我的绘图代码: TestObject = ggplot() + geom_polygon(data=Neth,

我制作了一张带有ggplot的地图,它根据我的数据框中的Freq值在地图上显示不同大小的点:

Longitude   Latitude    Result  Freq
4.690000    51.97400    Neg     1
6.040604    51.66494    Neg     23
6.87448     52.31593    Neg     4
我的绘图代码:

TestObject = ggplot() + 
  geom_polygon(data=Neth, 
               aes(long,lat,group=group), 
               fill="whitesmoke")+
  geom_path(data=Neth, 
            aes(long,lat, group=group), 
            color="black", size=0.3) +
  theme(aspect.ratio=1)+
  theme_opts + 
  geom_point(data=df, 
             aes(x=Longitude, y=Latitude, size=Freq),
             colour="red", fill = "violetred2", pch=21, alpha=I(0.65)) + 
  scale_size(range = c(3,10)) 
“Neth”是我下载的GADM地图。以下是我的ggplot与实际数据的关系:

当我在此ggplot上使用ggplotly时,指示点大小的图例消失:

ggplotly(TestObject, width=700, height=700)
这就是我的ggplotly最终的样子:


有什么方法可以将图例添加到此ggplotly或维护我的ggplot图例吗?

您可以将
布局作为
ggplotly(TestObject)%%>%layout(legend=list(orientation=“v”,x=1,y=0.5))
您可以将
布局作为
ggplotly(TestObject)%%>%layout(legend=list)添加到您的绘图中(方向=“v”,x=1,y=0.5))