Questions tagged [ggplotly]

ggplotly is a function which converts a ggplot object into an interactive plotly object. It enables the usage of functions like zoom, hover, playing with the axis, appearing/disappearing group of points.

For more information and examples, please visit the website.

799 questions
58
votes
4 answers

How to choose variable to display in tooltip when using ggplotly?

I have a simple data frame: seq <- 1:10 name <- c(paste0("company",1:10)) value <- c(250,125,50,40,40,30,20,20,10,10) d <- data.frame(seq,name,value) And I want to plot it this way: require(ggplot2) ggplot(data = d,aes(x=seq,y=value))+geom_line() +…
Malta
  • 1,883
  • 3
  • 17
  • 30
32
votes
1 answer

Highlight all values from a group on hover

Assume data library(ggplot2) library(plotly) set.seed(357) xy <- data.frame(letters = rep(c("a", "b", "c"), times = 3), values = runif(9), groups = rep(c("group1", "group2", "group3"), each = 3)) letters …
Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
19
votes
2 answers

Difference in legend position between ggplot and ggplotly?

I find out an interesting and strange difference between the same chart in ggplot and ggplotly income_gap_chart <- ggplot(income_gap, aes(x = Country, y = Percent, fill = Income)) + geom_bar(position = "dodge", stat = "identity")…
Anakin Skywalker
  • 2,400
  • 5
  • 35
  • 63
15
votes
5 answers

Strange formatting of legend in ggplotly in R

I'm trying to turn a ggplot into a plotly. The ggplot renders fine, but when I put it through ggplotly, suddenly the legend adds parenthesis and ",1" after the label. Here's a sample fake data: sorted1<-data.frame(CommDate=c(as.Date("2017-09-12"),…
iod
  • 7,412
  • 2
  • 17
  • 36
14
votes
3 answers

ggplot2 remove axis label

I have the following dataset: dput(head(active_clients)) structure(list(Date = structure(c(1422662400, 1425081600, 1427760000, 1430352000, 1433030400, 1435622400), class = c("POSIXct", "POSIXt" ), tzone = "UTC"), value = c(65139, 66615, 66669,…
Prometheus
  • 1,977
  • 3
  • 30
  • 57
10
votes
1 answer

ggplot geom_tile is distorted in ggplotly

I am trying to convert a geom_tile plot built with ggplot to ggplotly. However, the tiles are distorted in plotly. The same issues takes place with geom_raster. Showcase: library(ggplot2) library(plotly) set.seed(1) n <- 10 X <- data.frame(xcoord =…
mat
  • 2,412
  • 5
  • 31
  • 69
10
votes
2 answers

Combine ggplotly and ggplot with patchwork?

Is it possible to combine a ggplotly and a ggplot with patchwork? Example This displays the two plots side by side library(ggplot2) library(plotly) library(patchwork) a <- ggplot(data.frame(1), aes(X1)) + geom_bar() b <- ggplot(data.frame(1),…
dss
  • 395
  • 3
  • 11
10
votes
1 answer

Disable hover information for a specific layer (geom) of plotly

library(ggplot2) library(plotly) gg <- ggplot(mtcars, aes(factor(vs), drat)) + geom_violin() + geom_jitter() ggplotly(gg) In example code we use ggplot to plot violin and jitter layers. Plotly displays information for both layers (i.e.…
pogibas
  • 27,303
  • 19
  • 84
  • 117
9
votes
2 answers

Long facet_wrap labels in ggplotly / plotly overlap facet's strip.background

I've got a plot like the one below, where I need to display a plot title and some long facet labels. In ggplot2, it looks just fine. Reprex: library(ggplot2) library(stringr) library(plotly) iris$Species2 <- paste(iris$Species, "... some text to…
Nova
  • 5,423
  • 2
  • 42
  • 62
9
votes
3 answers

Add vertical line to ggplotly plot

I am trying to build a plot combining ggplot2 and plotly. The two vertical lines appear on pure ggplot2, but once I call plotly::ggplotly on it, they go away. How can I make the data also appear on the ggplotly version? If you have a solution using…
D Pinto
  • 871
  • 9
  • 27
9
votes
3 answers

How to use plotly to return the same event_data information for selected points even after modifying the data

I'm trying to do something seemingly simple: when the user clicks on a data point or select multiple points with lasso selection, I want to draw these points in a different colour. In order to do that, I look at what points are selected, and add a…
DeanAttali
  • 25,268
  • 10
  • 92
  • 118
9
votes
3 answers

ggplot2 + plotly : Axis title disappear

I've got an issue when using ggplotly() to a ggplot graph: the y axis disappears. Here's a reproducible example using iris dataset (this example is quite dump, but whatever) data(iris) g = ggplot(data = iris, aes(x = Petal.Length, y = Petal.Width,…
prise6
  • 136
  • 1
  • 7
8
votes
2 answers

Plotly: How do I set ylim and xlim for a map?

Aim: I am trying to create an interactive version of a ggplot2 map using plotly (via ggplotly). Problem: Plotly adds additional space above and below the chart rather than "stretching" the chart like it should (see images for example). Example What…
Blithering
  • 560
  • 5
  • 14
8
votes
1 answer

Improve performance of ggplotly when plotting time-series heatmap

I'm building an interactive time-series heatmap in R using Plotly and Shiny. As part of this process, I'm re-coding heatmap values from continuous to ordinal format - so I have a heatmap where six colours represent specific count categories, and…
Geek On Acid
  • 6,330
  • 4
  • 44
  • 64
8
votes
2 answers

Using `ggplotly` and `DT` from a `for` loop in Rmarkdown

Is that possible to use ggplotly() or datatable() in RMarkdown from inside a for loop or function? Example: --- title: "Using `ggplotly` and `DT` from a `for` loop in Rmarkdown" output: html_document --- ```{r setup,…
IVIM
  • 2,167
  • 1
  • 15
  • 41
1
2 3
53 54