0

I have a data frame df.europeCoords which looks like this:

enter image description here

And I plot a Europe map with the following code:

## Plot the map: ##
      p <- ggplot(data = df.europeCoords, aes(x = longitude, y = latitude, group = country, 
                                              fill = meanValues, text = paste("<b>", country, '</b>\n')),  
                  color = "black", size = 0.1) + 
           geom_polygon(aes(color = border), size = 0.4) +
           scale_color_manual(values = c(NA, color = "black", size = 1), guide = FALSE) + #guide = FALSE
           coord_map(xlim = c(15, 20),  ylim = c(32, 71)) +
           theme_classic() +
           scale_fill_gradient(name = "Price Mean Values", low = "#F9F7EA" , high = "#006E37",
                               na.value = "#CCCCCC") +      # #DCF1D5        #007d3c
           theme(axis.text.x = element_blank(), axis.text.y = element_blank(), 
                 axis.ticks.x = element_blank(), axis.ticks.y = element_blank(), 
                 axis.title = element_blank(),
                 plot.margin = unit(0 * c(-1.5, -1.5, -1.5, -1.5), "lines")) +
           geom_text(data = df.longLat, aes(x = long, y = lat, label = meanValues, fontface = "bold"), size = 3.5)
        
      ## Generate ggplot() to plot_ly() object: ##
      PowerEuropePlot <- plotly::ggplotly(p, tooltip = "text") %>%
                         layout(title = paste('<b>POWER Price Information</b>', 
                                              '\n<span style="font-size: 14px;">', 
                                              "SPOT",'\n</span>'), 
                                margin = list(t = 50),
                                xaxis = ax, yaxis = ax)

This yield the following plot:

enter image description here

I want to hide the red bordered legend, which already work when I have a look on p. I hide this legend with the following: scale_color_manual(values = c(NA, color = "black", size = 1), guide = FALSE), but when I use plotly::ggplotly(p, ...)the legend is shown, which is not what I want.

Why is this happening?

structure(list(longitude = c(20.5902474301049, 20.4631750830992, 
20.6051819190374, 21.0200403174764, 20.9999898617472, 20.6749967790636, 
20.6150004411728, 20.1500159034105, 19.9800004411701, 19.9600016618732
), latitude = c(41.8554041611336, 41.5150890162753, 41.0862263046852, 
40.8427269557259, 40.580003973954, 40.434999904943, 40.1100068222594, 
39.624997666984, 39.6949933945234, 39.915005805006), country = c("Albania", 
"Albania", "Albania", "Albania", "Albania", "Albania", "Albania", 
"Albania", "Albania", "Albania"), border = c(FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE), meanValues = c(NA_real_, 
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
NA_real_, NA_real_)), row.names = c(NA, 10L), class = "data.frame")
MikiK
  • 398
  • 6
  • 19
  • Does this answer your question? [Turning off some legends in a ggplot](https://stackoverflow.com/questions/14604435/turning-off-some-legends-in-a-ggplot) – Daman deep Nov 19 '20 at 09:25
  • @Damandeep unfortunately not! I have already tried all possible solutions from this post. As you can see I'm using ```guide=FALSE``` and this works for the ```ggplot()```. But when I convert the ```ggplot()``` to a ```plotly``` object then the legend is again shown. I need this convertion with```ggplotly()```. – MikiK Nov 19 '20 at 09:31
  • Try this add this argument `showlegend = FALSE`.Can you share data? That code is not going to work in my Rstudio without data. – Daman deep Nov 19 '20 at 09:34
  • I already tried it, and it doens't work. How can I share the data? Is it possible to give you the excel file? – MikiK Nov 19 '20 at 09:41
  • dput(your data) in R then share it. – Daman deep Nov 19 '20 at 10:03
  • @Damandeep, ```x <-dput(df.europeCoords)```, then ```x``` is a data frame, but how can I share the whole data frame? It is huge – MikiK Nov 19 '20 at 10:10
  • `dput(df.europeCoords)` after this command copy result from console and paste here and see [this](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Daman deep Nov 19 '20 at 10:12
  • The console doesn't show me the whole data frame. How can I copy then the whole data frame?? – MikiK Nov 19 '20 at 10:15
  • see link I have attached – Daman deep Nov 19 '20 at 10:16
  • @Damandeep I have now edited my question, but I don't know if this works for you, as I have for each country much more longitudes and latitudes as rows than here, which are now missing for this reproducible example data frame – MikiK Nov 19 '20 at 10:21
  • You have to make everything available for us to help you. – Daman deep Nov 19 '20 at 10:31
  • As I already mentioned, I can't copy the whole data frame from the console because the console doesn't show the whole data frame, so this doesn't work. – MikiK Nov 19 '20 at 10:34
  • `options("max.print" = 1000)` then copy it again the way u did. – Daman deep Nov 19 '20 at 10:39
  • @Damandeep doesn't change the output in console. – MikiK Nov 19 '20 at 12:18
  • @Damandeep `dput` has a `file` argument. Accordingly something like `dput(df.europeCoords, file = "europeCoords.txt")` should write the output of `dput` to a txt file. Then simply copy the output from the file. – ismirsehregal Jan 28 '21 at 08:19

0 Answers0