r-plotly

What exactly is the z argument in plot_ly?

你离开我真会死。 提交于 2021-02-08 13:48:38
问题 I have three variables: x , y , and z and I want to produce a surface plot. z<-runif(50,0,1) y<-runif(50,1,2) x<-runif(50,3,6) plot_ly(x = ~x, y = ~y, z= ~z) %>% add_surface() I get the following error Error: `z` must be a numeric matrix What exactly does z represent if not the variable corresponding to the vertical axis? I have seen the Volcano example where they use the matrix to generate that plot, but I still am not sure what that z matrix represents in that example either. What I would

Click-event not triggering inside a Plotly subplot within Shiny

允我心安 提交于 2021-02-08 06:47:50
问题 I'm creating a shiny app with 2 different tabs. Each of them has a couple of plotly plots. I want the plots to only react to the plotly_click events from the correspondent tab. My problem comes when instead of having separated plots, I want one of them to be part of a subplot. To do so, I have added the source parameter to the plots in order to distinguish which plot is the one that has been clicked. When the plots are individual plots (not inside a subplot) works nicely, but if I try to put

Click-event not triggering inside a Plotly subplot within Shiny

混江龙づ霸主 提交于 2021-02-08 06:47:48
问题 I'm creating a shiny app with 2 different tabs. Each of them has a couple of plotly plots. I want the plots to only react to the plotly_click events from the correspondent tab. My problem comes when instead of having separated plots, I want one of them to be part of a subplot. To do so, I have added the source parameter to the plots in order to distinguish which plot is the one that has been clicked. When the plots are individual plots (not inside a subplot) works nicely, but if I try to put

How to set different text and hoverinfo text

*爱你&永不变心* 提交于 2021-02-07 06:19:04
问题 I am working with the plotly package, and I cannot find a way to display different things on the chart itself and in the hoverinfo. Here is an example of a barchart: library(plotly) library(dplyr) data(iris) df <- iris %>% group_by(Species) %>% summarise(n = n(), avg = mean(Sepal.Length)) p1 <- plot_ly(data = df, x = ~Species, y = ~n, type = "bar", text = ~paste("Species :", Species, "<br> Avg :", avg), textposition = "auto", hoverinfo = "text") From this code I get this: And I would like to

Return datapoints selected in a plotly scatterplot

依然范特西╮ 提交于 2021-02-07 04:12:07
问题 I created a plotly scatterplot from a ggplot2 using ggplotly . I would like to obtain a table of the datapoints selected / zoomed into, but I can't find a way to do this. library(ggplot2) library(plotly) p <- ggplotly(plot.rel.kinship) htmlwidgets::saveWidget(as_widget(p), "scatterplot.html") There seems to be a similar unanswered question on the plotly forum: https://community.plot.ly/t/get-datapoints-in-currently-zoomed-view/259 This question also seems to be related: Using Plotly with DT

Return datapoints selected in a plotly scatterplot

家住魔仙堡 提交于 2021-02-07 04:07:59
问题 I created a plotly scatterplot from a ggplot2 using ggplotly . I would like to obtain a table of the datapoints selected / zoomed into, but I can't find a way to do this. library(ggplot2) library(plotly) p <- ggplotly(plot.rel.kinship) htmlwidgets::saveWidget(as_widget(p), "scatterplot.html") There seems to be a similar unanswered question on the plotly forum: https://community.plot.ly/t/get-datapoints-in-currently-zoomed-view/259 This question also seems to be related: Using Plotly with DT

Return datapoints selected in a plotly scatterplot

帅比萌擦擦* 提交于 2021-02-07 04:07:52
问题 I created a plotly scatterplot from a ggplot2 using ggplotly . I would like to obtain a table of the datapoints selected / zoomed into, but I can't find a way to do this. library(ggplot2) library(plotly) p <- ggplotly(plot.rel.kinship) htmlwidgets::saveWidget(as_widget(p), "scatterplot.html") There seems to be a similar unanswered question on the plotly forum: https://community.plot.ly/t/get-datapoints-in-currently-zoomed-view/259 This question also seems to be related: Using Plotly with DT

Colorbar in legend when using plotly

一个人想着一个人 提交于 2021-02-05 10:26:42
问题 Here is my data: set.seed(42) mydata = data.frame(A = rnorm(20), B = rnorm(20), Index = sample(190:400,20)) I am trying to divide the data into 20 different intervals based on the Index value and then color the scatter points according to their interval value . Below is my code. It is not working perfectly. cols = colorRampPalette(c("red", "black"), space = "rgb")(20) mydata$interval = cut(mydata$Index,breaks = 20) mydata$cols = cols[mydata$interval] require(plotly) x = list(title = "A") y =

Download data underlying plotly graph in R

我的梦境 提交于 2021-01-29 11:16:28
问题 I am using plotly in Rmarkdown. When I plot a graph, id there a way to download the underlying data ? library(plotly) x <- c(1:100) random_y <- rnorm(100, mean = 0) data <- data.frame(x, random_y) p <- plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines') Typically in the plot above I would like to get the data data.frame in some csv format 回答1: You can embed the CSV file into your Rmarkdown HTML using this function: yihui.name/en/2018/07/embed-file. 来源: https://stackoverflow

R: An interactive graph of a function with sliders in plotly

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 09:20:35
问题 To plot a function with its parameters being updated dynamically via sliders is easy in R using basic plot and 'manipulate' package. Here is an example of a sine wave with its amplitude and frequency being controlled by parameters A and k, respectively. library(manipulate) manipulate(plot(x, A*sin(k*x)), A = slider(1,3), k = slider(1,10)) However, the basic plot is not as pretty a plotly one. Is there a simple way to do it in plotly? Plotly provides examples of sliders on its site, but the