簡體   English   中英

R:圖例未顯示在 ggplotly map

[英]R: Legend not showing in ggplotly map

我用 ggplot 制作了一個 map,它根據我的 dataframe 中的頻率值在 map 上顯示不同大小的點:

Longitude   Latitude    Result  Freq
4.690000    51.97400    Neg     1
6.040604    51.66494    Neg     23
6.87448     52.31593    Neg     4

我的ggplot代碼:

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 map。 這是我的 ggplot 與我的實際數據的外觀:

ggplot 地圖

當我在這個 ggplot 上使用 ggplotly 時,我表示點大小的圖例消失了:

ggplotly(TestObject, width=700, height=700)

這就是我的 ggplotly 最終的樣子:

ggplotly 地圖

有什么方法可以向這個 ggplotly 添加圖例或維護我的 ggplot 圖例?

您可以將layout添加到 plotly 作為ggplotly(TestObject) %>% layout(legend=list(orientation = "v",x = 1, y = 0.5))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM