plotly

Building plotly graph in for loop not displaying all series

戏子无情 提交于 2019-12-04 03:42:46
问题 Creating a plot by adding one column at a time works just fine exPlot <- plot_ly(data.table(matrix(1:9,ncol = 3))) theCols <- c("V2","V3") exPlot <- exPlot %>% add_lines(x = ~V1, y = ~get(theCols[1]), type = "scatter",mode = "lines") exPlot <- exPlot %>% add_lines(x = ~V1, y = ~get(theCols[2]), type = "scatter",mode = "lines") exPlot but if I try to do the same thing in a for loop, it only displays the second trace, overwriting the first one. exPlot <- plot_ly(data.table(matrix(1:9,ncol = 3))

Cufflinks for plotly: setting cufflinks config options launches

大城市里の小女人 提交于 2019-12-04 03:36:07
I'm trying to use cufflinks locally to generate plotly graphs from a pandas Dataframe However, when I try and configure cufflinks in a python console, it then goes into ipython mode: >>> import cufflinks as cf >>> cf.set_config_file(offline=True) In : Subsequently, when I try and generate a plot, nothing appears: In : df.iplot(kind='bar', barmode='stack', filename='cufflinks/test') In : Can cufflinks be used offline without a plotly account? elsherbini I think the issue is setting the filename argument in the iplot call. df.iplot(kind='bar', barmode='stack') http://nbviewer.jupyter.org/gist

Multiple y-axes chart with Plotly in R

只谈情不闲聊 提交于 2019-12-04 03:32:15
In Plotly for Python, we have this beautiful multiple y-axis example: here is the link for the code. I tried to do the same with Plotly in R using this code: library(plotly) x <- 1:4 y1 <- c(1,2,3,4) y2 <- c(4,3,2,1) y3 <- c(1,4,1,4) y4 <- c(4,1,4,1) test <- data.frame(x, y1, y2, y3, y4) plot_ly(data = test, x = ~x, y = ~y1 ,type = "scatter", mode = "lines", width = 800, color = I("red") ,name = "name01") %>% add_trace(x = ~x, y = ~y2, yaxis = "y2", color = I("blue"), name = "name02") %>% add_trace(x = ~x, y = ~y3, yaxis = "y3", color = I("purple"), name = "name03") %>% add_trace(x = ~x, y =

Plotly R: setting the spacing between axis label and axis ticks labels

限于喜欢 提交于 2019-12-04 02:49:10
Is there any way to set a spacing between axis labels and axis ticks labels other than changing margins? Example plot: plot_ly(mtcars, x = ~ wt, y = ~ paste0(hp, '0000')) As in the example plot above the title of the y axis is overlapping tick labels of this axis. Is there a way to set a spacing between them? Increasing the left margin as @Codutie suggests in his answer does help to a certain degree only (at least in Plotly v4.7.1+). Most of the 150 pixel margin on the left is wasted space as can be seen in the screenshot below: R-code to generate the above plot (from @Codutie): library(plotly

Plotly - Surface - Text hoverinfo not working

送分小仙女□ 提交于 2019-12-04 02:01:48
问题 I have build a surface chart with plotly and I am trying to have hoverinfo based on my own text. Curiously it is not working anymore. library(plotly) x <- rnorm(10) y <- rnorm(10) z <- outer(y, x) p <- plot_ly(x = ~x, y = ~y, z = ~z, type = "surface", text = ~paste0("My X = ", x, "\n My Y = ", y, "\n My Z = ", z), hoverinfo = "text") %>% layout(dragmode = "turntable") print(p) Although p <- plot_ly(x = ~x, y = ~y, z = ~z, type = "surface") %>% layout(dragmode = "turntable") works well. I have

Set marker size in plotly

别等时光非礼了梦想. 提交于 2019-12-04 01:26:57
问题 How can I change the marker size in plotly in R on a map? If I set the size argument to any number it makes it the same, too big size. And if I map it to a variable in my data, the markers are to small to really be able to tell the difference in the first place. Ideally I would like to increase the base size and keep the proportional aspect through mapping to the variable. Reproducible example: library(data.table) library(plotly) library(dplyr) sample <- data.table(Region=c("Illinois",

R: ggplot and plotly axis margin won't change

巧了我就是萌 提交于 2019-12-04 00:23:01
问题 I'm having problems stopping the y-axis text from overlapping with the ticks using ggplotly around ggplot . How can I fix this? I've tried the following code: set.seed(395) df1<- data.frame(CO2= c(cumsum(rnorm(1*36)), cumsum(rnorm(1*36))), Group= rep(c("A","B"), each=36), Segment=rep(seq(1,12),each=36)) plot<-ggplot(df1, aes(CO2, fill = Group)) + geom_density(alpha = 0.8)+ facet_wrap(~ Segment)+ theme_bw()+ labs(x="CO2", y="density") #Shouldn't the following work? pb <- plotly_build(plot) pb

R - plotly - combine bubble and chorpleth map

余生颓废 提交于 2019-12-03 21:49:57
I would like to combine two types of maps within one map in plotly, namely bubble and choropleth map. The objective is to show population size on a country level (choropleth) as well as on a city level (bubble) by hovering with the mouse over the map. The plotly example code for a choropleth map is as follows: library(plotly) df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv') # light grey boundaries l <- list(color = toRGB("grey"), width = 0.5) # specify map projection/options g <- list( showframe = FALSE, showcoastlines = FALSE, projection

Error ggplotly: VECTOR_ELT() can only be applied to a 'list', not a 'NULL'

老子叫甜甜 提交于 2019-12-03 17:44:15
问题 I'm using R 3.3.3 and RStudio 1.0.136 , and the latest versions of all the packages. I get this error with the plotly package > ggiris <- qplot(Petal.Width, Sepal.Length, data = iris, color = Species) > ggplotly(ggiris) Error in grid.Call(L_convert, x, as.integer(whatfrom), as.integer(whatto), : VECTOR_ELT() can only be applied to a 'list', not a 'NULL' This error does not occur anymore after I "print" the ggplot: > ggiris > ggplotly(ggiris) It occurs not only in RStudio, but also in a Shiny

Adjust the size of plotly charts in slidify

故事扮演 提交于 2019-12-03 16:23:50
I've created a plotly chart in R and then save the plot via htmlwidget so the plot can called in slidify. I played with width and height , in both layout argument and index.Rmd to fit the plot on a slidify slide but the final result always cut the bottom portion of the chart when some texts are added together. How can I truly adjust the size of the plotly chart in slidify? The code in R script ## first slide date <- seq(from = as.POSIXct("2015/4/1"), to = as.POSIXct("2015/10/1"), by = "month") as.Date(date, "%Y/%m/%d") set.seed(2016) tot.prem <- runif(n = 7, min = 0, max = 1200) pol.frce <-