plotly

How to get coordinates from a R plotly figure

谁都会走 提交于 2019-12-23 12:34:04
问题 I have been struggling like mad to solve an apparently basic question. Imagine you have a scatter plot, with say ... 10 markers. I suppose this plot has been generated using plotly within a Shiny environment. One can easily get the coordinates of these markers using the event_data("plotly_click") code. Now imagine you do not need the coordinates of these markers, but the coordinates generated by a mouse click but precisely where no marker exists (for example because you would like to set a

geom_line not plotting when tooltip argument set in ggplotly

拈花ヽ惹草 提交于 2019-12-23 12:21:05
问题 I am trying to use plotly for interactive visuals in my shiny app. However, I am running into a problem when trying to add a custom tooltip to the graph. If i set the tooltip argument in ggplotly() then my geom_line() is ignored in my output but the tooltip works. Here is a MRE: library(shiny) library(ggplot2) library(plotly) library(tidyquant) #only using the palette_dark() function library(magrittr) graph <- data %>% ggplot(aes(date, result, text = paste0("Site: ", site, "\n", "Quarter: ",

Plotly: Parallel Coordinates Plot: Axis Styling

非 Y 不嫁゛ 提交于 2019-12-23 12:17:51
问题 I really like the parallel coordinates plot available in Plotly but I just ran into an issue I could use help with. Is it possible to have log10 based axis for some of the coordinates? As you can see in the example below performing a log10 transform allows to better distinguish the smaller values. However, by transforming the data we loose the ability to interpret the values. I would prefer to log scale the axis instead of the data but couldn't find a way to do this. I did find something

Retrieving R object attributes in JavaScript

落花浮王杯 提交于 2019-12-23 11:50:33
问题 I have a bivariate dataset with 100 observations. I used hexagon binning and ended up with 26 hexagon bins. In order to save the rows of the 100 observations that are in each of the 26 hexagon bins, I used the base::attr function in R. In the code below, this is done at: attr(hexdf, "cID") <- h@cID I am trying to create an interactive R Plotly object of the hexagon binning so that if a user were to click on a given hexagon bin, they would obtain the rows of the 100 observations that were

Separate symbol and color in plotly legend

你离开我真会死。 提交于 2019-12-23 09:18:32
问题 I want to achieve the same result as this ggplot code with plotly: mtcars %>% add_rownames('car') %>% ggplot(aes(x = mpg, y = disp, color = as.factor(gear), shape = as.factor(cyl))) + geom_point() which results in: My plotly code is: library(dplyr) mtcars %>% add_rownames('car') %>% plot_ly(x = ~mpg, y = ~disp, text = ~car, color = ~as.factor(gear), symbol = ~as.factor(cyl), mode = 'markers') which enumerates all possible combinations of colors and shapes in the legend. Is there a way to have

line break and subscript in axis title using plotly in R

两盒软妹~` 提交于 2019-12-23 09:02:11
问题 I just started to use plotly for some interactive scatter plots in R and having a hard time on axis labels. Normally I designed my plots with ggplot2 and then using the ggplotly function to convert them, but this is sometimes very slow for any reason. So I want to create my plots directly in plotly ... I am trying now to change the axis title and want to add line breaks and later I also want to add subscript labels. But I am already failing at the newline in the title. Is there any trick?

custom colors in R Plotly

泪湿孤枕 提交于 2019-12-23 08:27:40
问题 I'm currently a beginner in Plotly and have a problem I can't seem to solve. I have my plotly stacked bar chart but I don't know how to color each individual category. I am currently using R. This is my current stacked bar chart: My current code is: p = plot_ly(x, x = day, y = count, type = "bar", group = status) %>% layout(barmode = "stack", showlegend = T) I've tried using the "color = " parameter and also markers, but nothing correctly colors my graph. 回答1: You need to specify a factor for

Adding color and bubble size legend in R plotly

不问归期 提交于 2019-12-23 05:59:15
问题 Probably an easy one. I have an xy dataset I'd like to plot using R 's plotly . Here are the data: set.seed(1) df <- data.frame(x=1:10,y=runif(10,1,10),group=c(rep("A",9),"B"),group.size=as.integer(runif(10,1,10))) I'd like to color the data by df$group and have the size of the points follow df$group.size (i.e., a bubble plot). In addition, I'd like to have both legends added. This is my naive attempt: require(plotly) require(dplyr) main.plot <- plot_ly(type='scatter',mode="markers",color=~df

Generating Dropdown menu for Plotly charts

前提是你 提交于 2019-12-23 05:01:58
问题 This is my code for stock volatility for 10 stocks: ##------------producing stock volatility plot---------## p1 = ggplot(Closed_Price_Return, aes(Date, R.BPCL)) + geom_line(color = "blue") + theme_bw() p2 = ggplot(Closed_Price_Return, aes(Date, R.TCS)) + geom_line(color = "green") + theme_bw() p3 = ggplot(Closed_Price_Return, aes(Date, R.CIPLA)) + geom_line(color = "red") + theme_bw() p4 = ggplot(Closed_Price_Return, aes(Date, R.EICHER)) + geom_line(color = "pink") + theme_bw() p5 = ggplot

Generating Dropdown menu for Plotly charts

妖精的绣舞 提交于 2019-12-23 05:01:19
问题 This is my code for stock volatility for 10 stocks: ##------------producing stock volatility plot---------## p1 = ggplot(Closed_Price_Return, aes(Date, R.BPCL)) + geom_line(color = "blue") + theme_bw() p2 = ggplot(Closed_Price_Return, aes(Date, R.TCS)) + geom_line(color = "green") + theme_bw() p3 = ggplot(Closed_Price_Return, aes(Date, R.CIPLA)) + geom_line(color = "red") + theme_bw() p4 = ggplot(Closed_Price_Return, aes(Date, R.EICHER)) + geom_line(color = "pink") + theme_bw() p5 = ggplot