Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 205399

Plotly R with ggplot2: Use coord_polar in a geom_bar using plotly

$
0
0

Is there a simple way of using coord_polar() when doing a barplot in ggplot2 using plotly?

Example without using polar coordinates - It works

One could also add +coord_flip() and this would still work.

library(ggplot2)
library(plotly)
# Create fake data
df <- data.frame(
           genre=c("Pop", "HipHop", "Latin", "Pop", "Pop", "HipHop"), 
           artist=c("ArianaGrande", "ChrisBrown", "DaddyYankee", "EdSheeran", 
                    "LewisCapaldi", "ShawnMendes")
      )
# Create a ggplot bar plot in polar coordinates
p <- ggplot(data=df) + 
      geom_bar(aes(x=genre, fill=artist))
# Wrap it around plotly
ggplotly(p)

plotly

What I need

When we add coord_polar() it stops working. Is there a workaround? I get the following messages

Warning messages:
1: In min(z[["x"]]$dimension %()% z$x.range %||% z$x_range) :
  no non-missing arguments to min; returning Inf
2: In max(z[["x"]]$dimension %()% z$x.range %||% z$x_range) :
  no non-missing arguments to max; returning -Inf
3: In min(z[["y"]]$dimension %()% z$y.range %||% z$y_range) :
  no non-missing arguments to min; returning Inf
4: In max(z[["y"]]$dimension %()% z$y.range %||% z$y_range) :
  no non-missing arguments to max; returning -Inf

Viewing all articles
Browse latest Browse all 205399

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>