r-plotly

add_trace: control the color

帅比萌擦擦* 提交于 2019-12-11 01:32:38
问题 I have a plot where I have first trace in gray that will be overplotted by other traces in colors. My issue is that in plotly -version 4.7.1. as well as in version 4.8.0. I can't adjust the color. One year ago this code would work: mysim=data.frame(x=rep(1:4,4),y=rbinom(16,10,0.5),id=rep(1:4,each=4)) my_colors<-c( ## add the standard plotly colors '#1f77b4', #// muted blue '#ff7f0e', #// safety orange '#2ca02c', #// cooked asparagus green '#d62728' #// brick red ) plot_ly() %>% add_trace(x=1

Control which tick marks / labels appear on x-axis in plotly?

北城以北 提交于 2019-12-10 18:25:12
问题 I want to have control over which tick marks appear on the x-axis. The following code places tick marks in a sequence of 5 (at 5, 10, 15 ... 30) library(plotly) df <- data.frame(x = 1:30, y = sample(100:300, size = 30, replace = T)) p <- plot_ly(data = df, x = x, y = y, type = 'line') %>% layout(title = 'Example plot') p I need to place them in a sequence of 6 at 6, 12, 18, 24, 30. I've been browsing the documentation but I cannot seem to find what I need. In ggplot2 this can be done via

Plot ellipse3d in R plotly?

梦想的初衷 提交于 2019-12-10 10:54:25
问题 Package rgl includes a very useful function ellipse3d , which can return an ellipsoid that cover like 95% percent of the points in 3D. Then this object can be used in rgl::plot3d to plot it out. My question is that is it possible to convert the output of ellipse3d to something that can be plotted through js plotting packages like plotly? library(rgl) dt <- cbind(x = rnorm(100), y = rnorm(100), z = rnorm(100)) ellipse <- ellipse3d(cov(dt)) plot3d(dt) plot3d(ellipse, add = T, color = "red",

Plotting Ellipse3d in R Plotly with surface ellipse

扶醉桌前 提交于 2019-12-10 10:11:15
问题 Similar to the question here but this didn't give me excatly what I needed and I couldn't figure it out: Plot ellipse3d in R plotly?. I want to recreate rgl's ellipse3d and surface ellipsoid in plotly. I know there there was an anwer which allowed plotting of an ellipse but as individual opaque markers, I need to get it as a surface ellipsoid that's slightly opaque so I can still see the data points in the ellipsoid. I tried to figure out how dww's comment for "add_surface" instead works but

R plotly hover label text alignment

删除回忆录丶 提交于 2019-12-08 18:17:45
问题 I'm adding custom hover text for scatterplot points in a plotly graph in R. It appears to be aligning the text left, center, or right depending on whether the text box is shown to the right, center, or the left of the plot points, respectively. I'd prefer if the text was always aligned left regardless of the positioning of the box. I've been able to style the font, e.g. setting the color and size, but haven't been able to change the text alignment. Here's an MRE. I've removed the legend so

How to remove duplicate legend entries w/ plotly subplots()

为君一笑 提交于 2019-12-08 16:38:05
问题 How can I remove the duplicates in my legend when using plotly's subplots()? Here is my MWE: library(plotly) library(ggplot2) library(tidyr) mpg %>% group_by(class) %>% do(p = plot_ly(., x = ~cyl, y = ~displ, color = ~trans, type = 'bar')) %>% subplot(nrows = 2, shareX = TRUE, titleX = TRUE) %>% layout(barmode = 'stack') 回答1: Another workaround using the tidyverse . The following steps are added to the original MWE: Convert the trans column to a factor. Use tidyr's complete to fill (non-NA)

Getting separate axis labels on R plotly subplots

不问归期 提交于 2019-12-08 16:00:38
问题 When using the R plotly package version 4.5.6 I haven't been able to figure out how to get axis labels to appear when combining multiple plots using subplot . Here is an example where no x-axis labels appear. require(plotly) a <- data.frame(x1=1:3, y=30:32) b <- data.frame(x2=11:13, y=31:33) u <- plot_ly(a) u <- add_lines(u, x=~x1, y=~y) v <- plot_ly(b) v <- add_lines(v, x=~x2, y=~y) subplot(u, v, shareY=TRUE) 回答1: To get x-axis labels to show up with subplot , you can set titleX = TRUE . The

How to render a plotly plot with preset traces hidden i.e. 'legendonly' based on list

走远了吗. 提交于 2019-12-08 10:45:10
问题 Thanks to help on a previous question here I can now record in a list which traces are hidden in a plotly plot by reading out the legend list of TRUE/legendonly with a piece of javascript , which I use to change the list entries, and the color of associated buttons. What I'm now also looking to do, is to maintain that TRUE/legendonly status when the plot is re-rendered. In the dummy app below, the plot can be re-rendered with the switch actionbutton , which causes a re- render due to a change

Save .png by webshot in R

和自甴很熟 提交于 2019-12-08 07:57:22
问题 I'm using webshot to save a png file from HTML : p <- plot_ly(plotly::wind, r = ~r, t = ~t) %>% add_area(color = ~nms)%>% layout(radialaxis = list(ticksuffix = "%"), orientation = 270) saveWidget(as.widget(p), "temp.html") webshot("temp.html",file = "temp.png",cliprect = "viewport") This is giving me a plot like this. It returns a small image in the upper left corner. What should I do to have a full-size image in a center? 来源: https://stackoverflow.com/questions/48289771/save-png-by-webshot

Can't implement ggplotly on a plot with annotation_custom

耗尽温柔 提交于 2019-12-08 04:19:51
问题 I'm plotting a dataset of shot locations on an ice rink. I want to use plotly to enable users to see a description box once they hover over each point. I thought this would be done using the custom tooltip The ice rink is stored in a rink object. rink <- rasterGrob(readJPEG("full-rink.jpg")) Here is full-rink.jpg This is the first 5 rows of the dataset I'm working with: structure(list(game_date = structure(c(17674, 17674, 17674, 17674, 17674), class = "Date"), event_team = c("WSH", "WSH", "T