r-plotly

Plotly: How to add a median line on a box plot

北战南征 提交于 2020-05-13 18:18:21
问题 I would like to add trace of a median line on my box plot. like this Here are my plots so far: library(plotly) p <- plot_ly(y = ~rnorm(50), type = "box") %>% add_trace(y = ~rnorm(50, 1)) p 回答1: Just start out with a scatter plot using plot_ly(..., type='scatter', mode='lines', ...) , and follow up with one add_boxplot(...' inherit=FALSE, ...) per box plot. Here's how you do it for an entire data.frame : Complete code with sample data: library(dplyr) library(plotly) # data df <- data.frame

Plotly: How to add a median line on a box plot

╄→尐↘猪︶ㄣ 提交于 2020-05-13 18:18:08
问题 I would like to add trace of a median line on my box plot. like this Here are my plots so far: library(plotly) p <- plot_ly(y = ~rnorm(50), type = "box") %>% add_trace(y = ~rnorm(50, 1)) p 回答1: Just start out with a scatter plot using plot_ly(..., type='scatter', mode='lines', ...) , and follow up with one add_boxplot(...' inherit=FALSE, ...) per box plot. Here's how you do it for an entire data.frame : Complete code with sample data: library(dplyr) library(plotly) # data df <- data.frame

How to sort plotly stacked bar graph in r by y value?

亡梦爱人 提交于 2020-03-26 04:04:56
问题 I've got this graph and I want it to appear in Sam - Jhon - Paul order because that's going from highest to lowest cost, somebody could tell me how to order it by cost? Tried using code below in layout section but it didn't word. layout(yaxis = list(title = 'Cost'), xaxis = list(title = 'Parent', categoryorder = "array", categoryarray = ~cost), barmode = 'stack') 回答1: You are almost there. You just need to use the order of top_3$parent in your categoryarray instead of cost , as follows:

tooltip with names in a PCA plot

浪子不回头ぞ 提交于 2020-03-03 08:43:34
问题 I want to generate an interactive plot with ggplotly(). The tooltip should show me the name of the variable. interactive <- ggplotly(pca,dynamicTicks = T,tooltip = c("x","y",label = list)) pca is a visualization of a PCA. sub is a data.frame that contains variable names. sub <- PCA(dataframe) pca <- fviz_pca_ind(sub, pointsize = "cos2", pointshape = 21, fill = "#E7B800", repel = TRUE, # Avoid text overlapping (slow if many points) geom = c("text","point"), xlab = "PC1", ylab = "PC2",label =

Enable autoscale in plotly.r

戏子无情 提交于 2020-02-05 04:34:27
问题 In my flexdashboard I used "plotly" library to plot the graph. when the data is refreshing at that time the bar size get reduced. At that time when I clicked on "autoscale" option then it is working fine. My question is can we enable autoscale automatically by any option in plotly.r code ? 回答1: Try setting autorange = TRUE for both the x- and y-axis in the layout option. This solved the issue for me. Example: plot_ly(x, y, type = "bar") %>% layout(xaxis = list(autorange = TRUE), yaxis = list

How to draw ellipsoid with plotly

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-23 12:59:14
问题 Are there any way to plot a surface like ellipsoid with plotly 3D? Currently only surfaces of the form z=f(x,y) are discussed in the docs. There is also Mesh 3D, but I found no examples for it. It seem to be possible to make a triangulation of ellipsoid manually and then use Mesh to get ellipsoid, but it looks a bit difficult for me. Are there any better way to do it? 回答1: Okay, it is easier than I thought. There is alphahull option that asks plotly to calculate the corresponding

Specifying the colors in a Plotly Heatmap

僤鯓⒐⒋嵵緔 提交于 2020-01-21 10:30:36
问题 I currently have a Plotly heatmap with categorical axes. The heat map plots the individuals of a graph against themselves, with each pair of individuals having a integer value (the z-value, which is what is plotted on the heat map) assigned to that pair (it's a measure of how fair apart the pair our). Right now, the colors on the heat map are being automatically assigned. Unfortunately, I can't quite figure out how to specify the color scheme for such a heat map. Is it possible to specify the

Modifying individual tick labels in R Plotly

╄→尐↘猪︶ㄣ 提交于 2020-01-16 04:28:10
问题 Suppose I have some code such as, library(plotly) Animals <- c("giraffes", "orangutans", "monkeys") SF_Zoo <- c(20, 14, 23) LA_Zoo <- c(12, 18, 29) data <- data.frame(Animals, SF_Zoo, LA_Zoo) p <- plot_ly(data, x=~Animals, y=~SF_Zoo, type='bar', name='SF Zoo') %>% add_trace(y=~LA_Zoo, name='LA Zoo') %>% layout(yaxis=list(title='Count'), barmode='stack') I'm trying to figure out how I color the three x-axis labels (giraffes, monkeys, orangutans) different colors, I've been trying to do this by

How can I grab the row of data from a ggplotly in shiny

亡梦爱人 提交于 2020-01-15 06:56:33
问题 Code Below. I'm trying to use the plotly_click event to figure out what data is being selected. However, I can't figure out how to do it. The data provided by plotly_click is very minimal and doesn't include the grouping or groups at all. I don't have any JS experience, but I know there must be a way! My goal is to be able to select a data point and be able to grab the row it corresponds to in a data.frame d1 d1=structure(list(Topic = c("compensation", "manager", "benefits", "family",

Update plot from interactive table in html

依然范特西╮ 提交于 2020-01-15 06:38:08
问题 What I would like to be able to do is to update the plot based on the output from the (DT-)table after filtering in the html . For example - here is a screenshot of the table filtered for maz in the html: I would like the scatter plot to update to only show the values shown in the filtered table. Is this possible? I know I could achieve something like this using a shiny web app, but is it possible to embed some shiny code into the html to achieve this? (I have very limited experience using