ggplotly

Highlight all values from a group on hover

旧街凉风 提交于 2019-12-02 19:01:32
Assume data library(ggplot2) library(plotly) set.seed(357) xy <- data.frame(letters = rep(c("a", "b", "c"), times = 3), values = runif(9), groups = rep(c("group1", "group2", "group3"), each = 3)) letters values groups 1 a 0.9913409 group1 2 b 0.6245529 group1 3 c 0.5245744 group1 4 a 0.4601817 group2 5 b 0.2254525 group2 6 c 0.5898001 group2 7 a 0.1716801 group3 8 b 0.3195294 group3 9 c 0.8953055 group3 ggplotly( ggplot(xy, aes(x = letters, y = values, group = groups)) + theme_bw() + geom_point() ) My goal is to, on hover, highlight all points that belong to the same group. E.g. on hover over

Creating a dynamic chart displaying sequences of activities with their count in R

假如想象 提交于 2019-12-02 17:04:09
问题 If you run the R script below, the dataset "patients" is an eventlog of patients visiting a clinic and getting treatment. The trace explorer gets created as in the snapshot below with the tooltip displayed. Now in the "#Script for Frequency Percentage", you get the frequency percentage for each trace in the column "af_percent". My requirement is that, I just want to replace the "label = value" in the ggplot command below with corresponding frequency percentage of each trace. Please help.

Making a stacked bar plot based on ranges in R and plotly

流过昼夜 提交于 2019-12-02 13:19:03
I want to create a stacked bar chart in R and plotly using iris dataset. In the x-axis, I want to set limits like iris_limits below in the code and the y-axis should contain all the Sepal.Length values which fit into these ranges. I want to pass the values as a single vector. Also, if the limits can be made dynamic by understanding the range of the Sepal.Length instead of hard coding it, please help. I have written a basic script with values to give you an idea. Thanks. library(plotly) iris_limits <- c("1-4", "4-6", "6-8") sepal <- c(2.4,5.4,7.1) data <- data.frame(iris_limits, sepal) p <-

Shiny: How to change the shape and/or size of the clicked point?

旧街凉风 提交于 2019-12-02 11:58:03
问题 I would like to change the shape and size of the clicked point in the below plot. How to achieve it? For this toy plot, I have reduced the number of points from original 100k to 2k. So, the expected solution should be highly scalable and do not deviate from the original plot i.e., all the colors before and after the update of the click point should be the same. library(shiny) library(plotly) df <- data.frame(X=runif(2000,0,2), Y=runif(2000,0,20), Type=c(rep(c('Type1','Type2'),600), rep(c(

Creating a horizontal bar chart in R to display sequence of activities

六月ゝ 毕业季﹏ 提交于 2019-12-02 11:09:21
The dataset "patients" is an eventlog of patients visiting a clinic and getting treatment. The script below gives a data frame with traces or sequence of activities in the eventlog, trace_id and absolute frequency of the cases following the particular trace. I wish to create a dynamic horizontal bar chart using ggplot2 or plotly such that the traces are represented like the snapshot attached with the absolute frequency in % at the top of the bar with axes labels. Thanks and please help! library("bupaR") traces(patients, output_traces = T, output_cases = F) Hope this helps (I am not able to get

Creating a dynamic chart displaying sequences of activities with their count in R

那年仲夏 提交于 2019-12-02 09:21:18
If you run the R script below, the dataset "patients" is an eventlog of patients visiting a clinic and getting treatment. The trace explorer gets created as in the snapshot below with the tooltip displayed. Now in the "#Script for Frequency Percentage", you get the frequency percentage for each trace in the column "af_percent". My requirement is that, I just want to replace the "label = value" in the ggplot command below with corresponding frequency percentage of each trace. Please help. library(splitstackshape) library(scales) library(ggplot2) library(plotly) tr <- data.frame(traces(patients,

Strange formatting of legend in ggplotly in R

微笑、不失礼 提交于 2019-12-02 05:40:31
I'm trying to turn a ggplot into a plotly. The ggplot renders fine, but when I put it through ggplotly, suddenly the legend adds parenthesis and ",1" after the label. Here's a sample fake data: sorted1<-data.frame(CommDate=c(as.Date("2017-09-12"), as.Date("2017-10-15")), CommName=c("Foo", "Bar"), PubB4=c(2,3)) And here's the code I'm trying to run on it: ggplotly(ggplot(sorted1, aes(x=as.Date(CommDate), y=PubB4))+ geom_smooth(level=0.0, aes(colour="Moving average"), se=FALSE)+ geom_point(aes(fill=CommName), size=4)+ expand_limits(y=c(0,4.5))+ geom_line(mapping=aes(y=4),colour="orangered3",size

Arranging bars of a bar plot with “null” in Descending order in R

可紊 提交于 2019-12-02 05:26:16
问题 I want to create a bar plot with Descending bars, In the plot below, due to NA being present at 2nd spot in "a1" vector, it is pushed at the last when the plot is created. However, I want the NA bar to be present at the 2nd spot only, kindly help me here as I want to achieve this without modifying my data. library(ggplot2) library(plotly) a1 = c("A",NA,"B","C","D","F") b1 = c(165,154,134,110,94,78) a12 = data.frame(a1,b1,stringsAsFactors = FALSE) pp1 <<- ggplot(a12 , aes(x = reorder(a1,-b1),

Arranging bars of a bar plot with “null” in Descending order in R

a 夏天 提交于 2019-12-02 02:57:21
I want to create a bar plot with Descending bars, In the plot below, due to NA being present at 2nd spot in "a1" vector, it is pushed at the last when the plot is created. However, I want the NA bar to be present at the 2nd spot only, kindly help me here as I want to achieve this without modifying my data. library(ggplot2) library(plotly) a1 = c("A",NA,"B","C","D","F") b1 = c(165,154,134,110,94,78) a12 = data.frame(a1,b1,stringsAsFactors = FALSE) pp1 <<- ggplot(a12 , aes(x = reorder(a1,-b1), y = b1,text=paste("User: <br>",a1, "<br> Days: <br>", round(b1)))) + geom_bar(stat = "identity", fill =

Can't generate plotly interactive plots in Rmarkdown report

早过忘川 提交于 2019-12-01 08:12:55
问题 I have an Rmarkdown document with a plot made with plotly and would like to generate an html file. It works when I click on Knit to HTML in Rstudio, but not when I run the following on the command line: Rscript -e "require(knitr)" -e "require(markdown)" -e "knit('Untitled.Rmd', out='report.md')" -e "markdownToHTML('report.md', 'report.html')" After this, I have a report.html file which contains the plot generated with plotly, but it is not interactive. Does anyone know how to make it