r-plotly

Make subplots of plot_ly graph in R

心已入冬 提交于 2021-01-29 07:10:17
问题 I have a dataframe, which can be created in this way: x = data.frame(metrics=c("type1", "type1", "type1", "orders", "orders", "orders", "mean","mean","mean"), hr=c(6,7,8,6,7,8,6,7,8), actual=c(14,20,34,56,12,34,56,78,89)) I tried to draw a scatterplot using plot_ly function. I wrote a function for it (i need it to be a function): plot <- function(df){ gp <- df %>% plot_ly( x = ~ hr, y = ~ actual, group = ~ metrics, hoverinfo = "text", hovertemplate = paste( "<b>%{text}</b><br>", "%{xaxis

Add a permanent contour line to a surface plot in R plotly

走远了吗. 提交于 2021-01-29 06:36:28
问题 I am using the plotly package in R to draw a surface plot and a contour plot: # Load package library(plotly) # Simulate the data for plotting x <- y <- seq(from = 0, to = 100, by = 1) z1 <- outer(X = x, Y = y, FUN = function(x, y) x^0.2 * y^0.3) # data for surface plot # Draw surface plot (3D) plotly::plot_ly(z = z1) %>% plotly::add_surface( contours = list( z = list( show = TRUE, usecolormap = TRUE, highlightcolor = "#ff0000", project = list(z = TRUE) ) ) ) # Draw contour plot (2D) plot_ly(z

Plotly subplots with shared legend in R

故事扮演 提交于 2021-01-28 09:02:03
问题 I have made twoplots using plotly, which are working fine individually, but when combined using subplot I can't seem to figure out how to combine the legends. I have tried to use showlegend = F in plot_ly in one of the plots, but this just removes it completely - what I want is to control both subplots with the same legend. My code is as follows: coronavirus_not_china <- coronavirus %>% filter(!(country == "China")) cases_not_china_plot <- coronavirus_not_china %>% group_by(type, date) %>%

define color scheme when plotting line plot with plotly

爱⌒轻易说出口 提交于 2021-01-28 07:41:27
问题 I have the following data table (which is not always the same, and has always a different number of columns) and code for plotting a line chart: dt <- data.table(date = seq(as.Date('2020-01-01'), by = '1 day', length.out = 365), Germany = rnorm(365, 2, 1), Austria = rnorm(365, 3, 4), Czechia = rnorm(365, 2, 3), check.names = FALSE) colNames <- names(dt)[-1] ## assuming date is the first column p <- plotly::plot_ly() for(trace in colNames){ p <- p %>% plotly::add_trace(data = dt, x = ~date, y

Multiple lines/traces for each button in a Plotly drop down menu in R

耗尽温柔 提交于 2021-01-28 05:10:55
问题 I am trying to generate multiple graphs in Plotly for 30 different sales offices. Each graph would have 3 lines: sales, COGS, and inventory. I would like to keep this on one graph with 30 buttons for the different offices. This is the closest solution I could find on SO: ## Create random data. cols holds the parameter that should be switched l <- lapply(1:100, function(i) rnorm(100)) df <- as.data.frame(l) cols <- paste0(letters, 1:100) colnames(df) <- cols df[["c"]] <- 1:100 ## Add trace

Ggplotly with tooltip has problems using geom_rect()

有些话、适合烂在心里 提交于 2021-01-27 20:05:23
问题 I am trying to plot some data in a ggplotly plot. The x-axis contains dates. Ggplotly doesn't work well with dates as when I hover over a point, the date is displayed as a number. I solved this by setting a tooltip like below. Some sample data: x <- data.frame(Date = as.Date(seq(Sys.Date(), Sys.Date() + 29, by = "days")), Amount = seq(-10000, 19000, by = 1000), stringsAsFactors = FALSE) The plot: ggplotly(ggplot(x, aes(x = Date, y = Amount, group = 1, text = paste("Date: ", Date, "<br>Amount:

How can I customize the modebar in plotly (preferably in R)?

孤街醉人 提交于 2021-01-27 12:10:21
问题 In particular, I am looking for a way to hide all buttons except the download image button. I tried to use the config argument but so far only managed to hide the entire modebar using displayModeBar = F . Any help would be highly appreciated. 回答1: Here's what you are looking for: plot_ly(economics, x = ~pop) %>% config(displaylogo = FALSE, collaborate = FALSE, modeBarButtonsToRemove = c( 'sendDataToCloud', 'autoScale2d', 'resetScale2d', 'toggleSpikelines', 'hoverClosestCartesian',

Open tab by clicking on a stacked barchart

我与影子孤独终老i 提交于 2021-01-22 10:47:48
问题 I'm building a stacked barchart containing retweets using R, ggplot and plotly. If a part of a barchart is clicked on, I want a new browser tab to open and show the tweet from this specific date with the indicated amount of retweets. However, when I click on one of the bars in the example below, a different link is opened, indicating that the url´s are not properly connected with the bars. How do I solve this? I have never worked or even seen JavaScript before, so chances are high the answer

R: Overlaying Points on a Graph

回眸只為那壹抹淺笑 提交于 2021-01-20 09:42:18
问题 This bounty has ended . Answers to this question are eligible for a +50 reputation bounty. Bounty grace period ends in 15 hours . stats555 wants to draw more attention to this question: Hello! I am trying to figure out a way to show the distribution of points between the minimum and the maximum values of a time series graph (using the R program language, using the "plotly" library). I have figured out how to plot the maximum and minimum value, and then show an interval between these points -

R: saving multiple html widgets together

别说谁变了你拦得住时间么 提交于 2021-01-12 06:17:25
问题 I am using the R programming language. I am interested in learning how to save several "html widgets" together. I have been able to manually create different types of html widgets: #widget 1 library(htmlwidgets) library(leaflet) library(RColorBrewer) # create map data map_data <- data.frame( "Lati" = c(43.6426, 43.6424, 43.6544, 43.6452, 43.6629), "Longi" = c(-79.3871, -79.3860, -79.3807, -79.3806, -79.3957), "Job" = c("Economist", "Economist", "Teacher", "Teacher", "Lawyer"), "First_Name" =