R: ggplot2 & Plotly: Recreating 'reference bands' on bar graphs from Tableau in R -


i trying recreate functionality use daily in tableau r (ggplot2 , plotly). need able create reference bands , lines similar image below. i've figured out how create reference lines geom_errorbar(). can't seem find solution 'reference band'.

if solution isn't possible in ggplot2 or plotly open package, need somethign static rmarkdown reports , dynamic html widgets dashboard.

below have sample code, add reference bands of 'high' , 'low' bar graph each person.

library(ggplot2)  #create data name <- c("rick","carl","daryl","glenn") pos <- c("m","m","d","d") load <- c(100,110,90,130) high <- c(150,160,130,140) low <- c(130,145,120,130) data <- data.frame(name,pos,load,high,low) rm(name,pos,load,high,low)   #create plot ggplot(data = data, aes(x = name, y = load)) +     geom_bar(stat ="identity", width=.4)  

could guidance appreciated. thank you!

enter image description here

geom_rect() better choise geom_errorbar() because can reproduce same image posted. take @ both rect , errorbar documentarion.

the following example used in markdown:

library(dplyr) library(ggplot2)  delta <- 0.5 data <- mtcars %>% group_by(cyl, vs) %>%   summarise(xmin = first(cyl) - 1,             xmax = first(cyl) + 1,             wt = mean(wt),             ymin = wt - delta,             ymax = wt + delta)  ggplot(data = data, aes(x = cyl, y = wt)) +   geom_rect(aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax),             fill = "indianred", alpha = 0.4) + # adds reference band layer before   geom_bar(stat = "identity", fill = "darkblue", width = 1) + # bar layer   facet_wrap(~vs) + theme_classic() 

enter image description here

if wish 1 reference band have use same ymax , ymin parameters observations.

you still need more effort in html version, because plotly::ggplotly() messing up.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -