plotly

R Plotly Deselect trace by default

帅比萌擦擦* 提交于 2019-12-30 06:47:42
问题 I am ussing R Plotly and have a line of the form: add_trace(y = meanRank, x = DateOnly, data = timeSeriesDF, name = "Daily Value", text = hoverText, hoverinfo = "text", showlegend = TRUE) It works fine. However, I want this trace to be "unselected" when the plot is shown. So a user would click it on the legend to show the line. I can't seem to find the parameter to show that. 回答1: You could add visible = "legendonly" : library(plotly) economics %>% transform(rate = unemploy / pop) %>% plot_ly

Edit labels in tooltip for plotly maps using ggplot2 in r

醉酒当歌 提交于 2019-12-30 03:28:05
问题 I know this question has been asked a number of times but I think some of the underlying syntax for plotly has changed since those questions have been asked. Using ggplotly() to create a choropleth map gives the default tooltip of long, lat, group, and one of my variables from my aesthetics. I understand that tooltip maps only whats in the aesthetics. All I want to do is to customize the tooltip so it displays some of the variables in my dataset (including those not mapped to aesthetics) and

Grouped line plots in Plotly R: how to control line color?

大兔子大兔子 提交于 2019-12-29 09:21:54
问题 I have a bunch of 'paired' observations from a study for the same subject, and I am trying to build a spaghetti plot to visualize these observations as follows: library(plotly) df <- data.frame(id = rep(1:10, 2), type = c(rep('a', 10), rep('b', 10)), state = rep(c(0, 1), 10), values = c(rnorm(10, 2, 0.5), rnorm(10, -2, 0.5))) df <- df[order(df$id), ] plot_ly(df, x = type, y = values, group = id, type = 'line') %>% layout(showlegend = FALSE) It produces the correct plot I am seeking. But, the

Grouped line plots in Plotly R: how to control line color?

纵然是瞬间 提交于 2019-12-29 09:21:07
问题 I have a bunch of 'paired' observations from a study for the same subject, and I am trying to build a spaghetti plot to visualize these observations as follows: library(plotly) df <- data.frame(id = rep(1:10, 2), type = c(rep('a', 10), rep('b', 10)), state = rep(c(0, 1), 10), values = c(rnorm(10, 2, 0.5), rnorm(10, -2, 0.5))) df <- df[order(df$id), ] plot_ly(df, x = type, y = values, group = id, type = 'line') %>% layout(showlegend = FALSE) It produces the correct plot I am seeking. But, the

Plotly R: Cant get points to plot when two values present per x factor level

偶尔善良 提交于 2019-12-29 08:17:26
问题 I have a data frame like this: dput(df) structure(list(x = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), .Label = c("41197708", "41223094", "41244000", "41244435", "41244936"), class = "factor"), y = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2)), .Names = c("x", "y"), row.names = c(NA, -10L), class = "data.frame") Trying to print a scatter plot with points as follows: plot_ly(df, x = levels(x), y = y, mode = 'markers') I only see points corresponding to y = 1 and not y = 2. Any idea why? The

Displaying image on point hover in Plotly

ⅰ亾dé卋堺 提交于 2019-12-29 05:17:05
问题 Plotly allows you to display text fields when hovering over a point on a scatterplot. Is it possible to instead display an image associated with each point when the user hovers over or clicks on it? I am mostly just using the web interface, but I could instead push my ggplot from R. 回答1: Unfortunately, there is no easy way to display images on hover on plotly graphs at the moment. If you are willing to learn some javascript, plotly's embed API allows you to customize hover (as well as click)

Add Regression Plane to 3d Scatter Plot in Plotly

拜拜、爱过 提交于 2019-12-29 04:45:06
问题 I am looking to take advantage of the awesome features in Plotly but I am having a hard time figuring out how to add a regression plane to a 3d scatter plot. Here is an example of how to get started with the 3d plot, does anyone know how to take it the next step and add the plane? library(plotly) data(iris) iris_plot <- plot_ly(my_df, x = Sepal.Length, y = Sepal.Width, z = Petal.Length, type = "scatter3d", mode = "markers") petal_lm <- lm(Petal.Length ~ 0 + Sepal.Length + Sepal.Width, data =

dynamically adjust height and/or width of shiny-plotly output based on window size

瘦欲@ 提交于 2019-12-28 16:07:05
问题 I would like to have the shiny-plotly output height and width adjusted to the current window size. I have tried to use the below but of no use. ShinyUi <- fluidPage( # Application title titlePanel("title"), sidebarLayout( sidebarPanel( ... inputs ... ), mainPanel( plotlyOutput("distPlot", height = 'auto', width = 'auto') ) )) ShinyServer <- function(input, output, session) { output$distPlot <- renderPlotly({ p <- ggplot(dataShow, aes(x=dataShow$X, y=dataShow$Y)) + geom_point(shape=1, alpha =

Ordering in r plotly barchart

半世苍凉 提交于 2019-12-28 06:19:06
问题 Why do I get the different order in plotly bar chart than I defined in x and y variables. E.g. library(plotly) plot_ly( x = c("giraffes", "orangutans", "monkeys"), y = c(20, 14, 23), name = "SF Zoo", type = "bar" ) I need bar chart where I see bars in the same order as x variable (categorical) is defined. Is there any trick for that? 回答1: plotly does it in alphabetical order. If you want to change it, just try to change levels of factor. This would be possible if you give your data in the

First time working with interactive plots in ggplotly, would like some feedback on my plot

柔情痞子 提交于 2019-12-25 18:22:07
问题 This is my first time working with ggplot2/ggploty() and would like some feedback as to what I could do to make my plot better. This is the code i've used: # interactive plot with ribbon test <- ggplot(data = wide.data, aes(x = x, y = pred)) + geom_ribbon(aes(ymin = lwr, ymax = upr, fill = model), alpha = .5) + geom_point(aes( group = model, fill = model)) + labs(x = "Number of Games Played", y = "Total Number of Goals") + scale_y_continuous(breaks=seq(0,70,5)) + scale_x_continuous(breaks=seq