plotly

Using both group and color in plotly

十年热恋 提交于 2019-12-07 21:45:17
问题 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:

In plotly, how do I create a linked X axis?

你说的曾经没有我的故事 提交于 2019-12-07 21:31:09
问题 import matplotlib.pyplot as plt import numpy as np import plotly.plotly as py from plotly.graph_objs import * py.sign_in('uname', 'pass') trace1 = Scatter( x=[1,2,3,4,5,6,7,8], y=[24,25,30,21,33,31,30,29], mode='lines', xaxis='x1', ) layout = Layout( title="My first plot", yaxis=YAxis( title = "y1" ), xaxis=XAxis( title= 'x1', anchor = 'x2' ), xaxis2=XAxis( title= 'x2', side = 'top', overlaying = 'y' ), ) data = [trace1] fig = Figure(data=data, layout=layout) plot_url = py.plot(fig) I am

Plotly Python: Align X-Axes in a grouped bar chart with multiple Y-axis

末鹿安然 提交于 2019-12-07 20:19:25
I have a grouped bar chart with two y axis each of them on a different scale. I am trying to align x-axis(y=0) of both the groups. I found few links link1 and link2 in which setting rangemode='zero' should work, however my data consists of negative values due to which I guess setting rangemode to zero isn't working. Here is my code: import plotly.offline as plt import plotly.graph_objs as go traces = [go.Bar(x=[1,2,3,4], y=[-1,2,-3,4], name='y actual'), go.Bar(x=[1], y=[0], name='y dummy', hoverinfo='none', showlegend=False), go.Bar(x=[1],y=[0],yaxis='y2', name='y2 dummy', hoverinfo='none',

Plotly: How to combine make_subplots() and ff.create_distplot()?

☆樱花仙子☆ 提交于 2019-12-07 19:57:45
问题 Creating multiple subplots using plotly is both easy and elegant. Consider the following example that plots two series from a dataframe side by side: Plot: Code: # imports from plotly.subplots import make_subplots import plotly.figure_factory as ff import plotly.graph_objs as go import pandas as pd import numpy as np # data np.random.seed(123) frame_rows = 40 n_plots = 6 #frame_columns = ['V_'+str(e) for e in list(range(1,n_plots+1))] frame_columns = ['V_1', 'V_2'] df = pd.DataFrame(np.random

Using Plotly with DT via crosstalk in Shiny

陌路散爱 提交于 2019-12-07 18:48:35
问题 I am writing an app to read a csv file into shiny and link a plotly scatter plot with a DT table. I pretty much followed the example from the Plotly website on DT datatable (https://plot.ly/r/datatable/) with the exception that the saved data from the csv is saved as a reactive input and that I have selectinput for the x and y variables for the scatterplot. I can generate the plot and DT table after clicking on the action button and I can also update the DT to only show selected rows from

R plotly add_trace to a chart with color groups

只谈情不闲聊 提交于 2019-12-07 18:35:42
问题 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? 回答1: Option 1: library(plotly) library(ggplot2) p <- ggplot(mtcars) + geom_point(aes(x = wt, y = mpg, col = am)) +

R Shiny to select traces for Plotly line chart?

跟風遠走 提交于 2019-12-07 18:07:04
问题 I am trying to use Shiny to select variables I want to plot in a multi-line chart rendered using Plotly. I have many variables so I want to select using Shiny instead of using Plotly's interactive legend "click" selection mechanism. Example Data: library(plotly) # Example dataframe foo <-data.frame( mon = c("Jan", "Feb", "Mar"), var_1 = c(100, 200, 300), var_b = c(80, 250, 280), var_three = c(150, 120,201) ) When using Plotly directly I can manually add traces using code like this: p <- plot

Custom discrete color scale in plotly

放肆的年华 提交于 2019-12-07 17:57:26
I would like to customize the colors in a plotly plot. This works fine for continuous variables and scales as per the docs : library(plotly) plot_ly(iris, x = Petal.Length, y = Petal.Width, color = Sepal.Length, colors = c("#132B43", "#56B1F7"), mode = "markers") If I make the argument to color discrete (character or factor), however, this still works but throws a warning: > plot_ly(iris, x = Petal.Length, y = Petal.Width, color = Sepal.Length>6, colors = c("#132B43", "#56B1F7"), mode = "markers") Warning message: In RColorBrewer::brewer.pal(N, "Set2") : minimal value for n is 3, returning

Same color assigned to same level of factor in R plotly

◇◆丶佛笑我妖孽 提交于 2019-12-07 17:43:25
I have a Shiny app with several plotly visualisations. The user is allowed to choose several products and I would like each product to have the same unique color throughout the entire app. One of my visualisations could e.g. look like this: plot_ly(df, x = variable, y=value, type = "bar", color = Product, hoverinfo = "text", colors = colpal, text = paste0(df$value,"%")) %>% layout(xaxis=ax, yaxis=yx, legend=list(x=1, y = 0.5)) Is it possible to make sure that the first level of Product ALWAYS get the first value of colpal? In ggplot I think this can be achieved by specifying the color pallette

python plotly: how to make a choropleth map with a slider (access grid data issue)

南楼画角 提交于 2019-12-07 17:41:00
问题 I want to draw a choropleth world map with a slider for the year values. It would be a combination of the "Choropleth Map" and the "Adding Sliders to Animations" (https://plot.ly/python/). First I searched plotly's community forum and the web for an example of a plotly choropleth map with grid data or a slider without success. While I managed to replicate the slider animation example with my data (see jupyter notebook link below), adapting the choropleth code to access grid data with a slider