plotly

Setting ranges for a bar chart in R and displaying count of items

丶灬走出姿态 提交于 2019-12-06 15:21:41
I have created a data frame from iris dataset using the following command: new_iris = data.frame(iris$Species,iris$Sepal.Length) range(iris$Sepal.Length) The second command tells me the range of the Sepal.Length. I want to implement a bar plot using plotly or ggplot2 such that the code decides the ranges of Sepal.Length automatically and then each range contains one bar which gives the count of all the Sepal.Length values in that range. So let's say if the ranges decided are "2-4","4-6","6-8", I should get 3 bars which give me a count of all the sepal.length values between "2-4","4-6" and "6-8

How to add arrow below the y axis in plotly 3D scatter plot?

可紊 提交于 2019-12-06 15:11:01
Creating 3D scatter plot with annotation by plotly can be done following the example: library(plotly) whole_dat = data.frame(x1 = rnorm(50), y1 = rnorm(50), z1 = rnorm(50)) p <- plot_ly() %>% add_markers( x = whole_dat$x1, y = whole_dat$y1, z = whole_dat$z1) p = layout(p, scene = list( annotations = list(list( x = 0.3, y = -3, z = -0.1, text = "12345", textangle= 0, ax = 0, ay = -75, xref='x', axref='x', yref = 'paper', ayref = 'paper', zref = 'paper', #showarrow=TRUE, arrowcolor= "black", arrowsize= 3, arrowwidth= 1, arrowhead= 1 )) ) ) htmlwidgets::saveWidget(as_widget(p), "test.html")

Coloring the axis tick text by multiple colors

你说的曾经没有我的故事 提交于 2019-12-06 14:54:26
I'm trying to plot a heatmap using R 's plotly package, where I'd like to have specific colors to specific labels of the y-axis tick text. Here's an example dataset: set.seed(1) df <- reshape2::melt(matrix(rnorm(100),10,10,dimnames = list(paste0("G",1:10),paste0("S",1:10)))) And here's what I'm trying: library(plotly) library(dplyr) plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) %>% layout(yaxis=list(title=list(color=c(rep("darkred",5),rep("darkblue",5))))) It's not working since

Graphing date vs time on plotly

亡梦爱人 提交于 2019-12-06 14:28:45
I have several data sets I would like to plot with dates as X axis and times as Y axis. I am working in Jupyter Notebook. from datetime import date, time from plotly import offline as py from plotly.graph_objs import Scatter, Data py.init_notebook_mode(connected=True) meetings = Scatter( x=[date(2017, 1, 1), date(2017, 1, 3), date(2017, 1, 3)], y=[time(8, 0, 0), time(12, 0, 0), time(16, 0, 0)], text=['work meeting 1', 'work meeting 1', 'work meeting 1'], mode='markers' ) workouts = Scatter( x=[date(2017, 1, 1), date(2017, 1, 2), date(2017, 1, 2)], y=[time(7, 30, 0), time(14, 30, 0), time(17, 0

3D interactive surface plot with spatial data

岁酱吖の 提交于 2019-12-06 14:15:35
I would like to create an interactive 3D surface plot of depths in a lake, ideally using the plotly or rgl libraries. I have extracted my data from a SpatialLinesDataFrame of contour lines in Gauss-Krueger/EPSG:31468 CRS, i.e. metric units. Now each contour line produces a set of coordinates with the same depth value. The resulting data frame is rather large, but looks something like this: set.seed(41) xx <- rnorm(100,4448929,100) yy <- rnorm(100,5308097,100) zz <- c(rep(-10,10),rep(-20,10),rep(-30,10),rep(-40,10),rep(-50,10),rep(-60,10),rep(-70,10),rep(-80,10),rep(-90,10),rep(-100,10)) df <-

Reduce number of gridlines in plotly scatter plots with log scale in R shiny

不羁岁月 提交于 2019-12-06 14:13:16
I've build the following test app where I solve the issue to get the tick labels as scientific annotation, but I would now like to reduce the number of grid lines to only be placed at the "main" ticks, i.e. the ones that have a text label. This question was posted based on discussion / comment on this previous SO question I would like to find a way that works for both 2D and 3D plotly scatter plots since I am using both. Here is the 3D app. library(shiny) library(plotly) shinyApp( ui = fluidPage( plotlyOutput('plot') ), server = function(input, output) { output$plot <- renderPlotly ({ mtcars <

R plotly add_trace to a chart with color groups

回眸只為那壹抹淺笑 提交于 2019-12-06 13:48:26
For data set mtcars , I want to plot a scatter plot ( wt v.s. mpg ) with am as the color group. Then I want to add a trace from (2,15) to (3,25). mtcars$am = as.character(mtcars$am) plot_ly(mtcars,x = ~ wt, y= ~ mpg, color = ~ am, type='scatter', mode = 'markers') %>% add_trace(x = c(2,15), y = c(3,25), mode="lines") The code without add_trace works fine. How to add this line? Option 1: library(plotly) library(ggplot2) p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, col = am)) + geom_segment(aes(x = 2, y = 3, xend = 15, yend = 25)) ggplotly(p) Option 2: plot_ly() %>% add_trace(data =

plotly not creating linear trend line

丶灬走出姿态 提交于 2019-12-06 13:22:04
In creating a trend line for a scatter plot, I am using add_trace to add a linear trend line. When the data only has one "series" of data, i.e. there is only one group of coordinates, the code below works fine. However, when I introduce a number of series, the "trend line" looks like this: Here is the relevant part of the code: p <- plot_ly(filteredFull(), x=Relative.Time.Progress, y=cumul.ans.keystroke, mode='markers', color=KeystrokeRate, size=KeystrokeRate, marker=list(sizeref=100), type='scatter', hoverinfo='text', text=paste("token: ",Token, "Keystrokes: ", KeystrokeCount)) %>% layout(

Using both group and color in plotly

元气小坏坏 提交于 2019-12-06 12:38:29
I am trying to plot a number of dimensions in r using plotly - is it possible to use both color and group parameters on factor variables to have a line that changes color? Example: grp <- c(letters[c(1,1,1,1,2,2,2,2)]) a <- c(1,2,3,4,2,3,4,5) b <- c(1,3,5,6,1,2,4,4) lvl <- c(1,1,2,2,1,1,2,2) df <- data.frame(grp, a, b, lvl) When plotting this using ggplot() I am able to create the desired effect as below, with grp as to define each line and lvl to define the color of sections of the line: ggplot(data = df, aes(x = a, y = b, group = grp, color = lvl)) + geom_line() + geom_point() However, when

Disable hover information for a specific layer (geom) of plotly

断了今生、忘了曾经 提交于 2019-12-06 12:09:31
library(ggplot2) library(plotly) gg <- ggplot(mtcars, aes(factor(vs), drat)) + geom_violin() + geom_jitter() ggplotly(gg) In example code we use ggplot to plot violin and jitter layers. Plotly displays information for both layers (i.e. when hovered over jitter point it will display specific point information, same thing happens when hovered over the violin plot). However, I want plotly to display information only for geom_jitter . Question: How to disable hovered information for specific layer? You can set the hoverinfo to "none" for that geom : gg <- ggplot(mtcars, aes(factor(vs), drat)) +