Skip to content

interest in R's ggridges implementation in Plotly #1285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dbo99 opened this issue Jun 8, 2018 · 2 comments
Closed

interest in R's ggridges implementation in Plotly #1285

dbo99 opened this issue Jun 8, 2018 · 2 comments

Comments

@dbo99
Copy link

dbo99 commented Jun 8, 2018

Just a huge fan of Plotly and basically all of the ggridges plots, showing my interest here.

here's an example function:

pdr_ann_perav_wysum_taf_d <- function(df) {
df_mn <- df %>% group_by(dv,scen) %>% summarize(annmean = 12*mean(taf))
df_md <- df %>% group_by(dv,scen,wy) %>% summarize(wysumtaf = sum(taf)) %>% group_by(scen, dv) %>% summarize(median = median(wysumtaf))
df %>% filter(kind != "storage") %>% group_by(scen, dv, wy) %>% summarize(wytafsum = sum(taf))
%>%
ggplot(aes(x=wytafsum, y=scen, color=dv, point_color=dv, fill=dv)) +
geom_density_ridges(jittered_points=TRUE, scale = .95, rel_min_height = .01,
point_shape = "|", point_size = 3, size = 0.25,
position = position_points_jitter(height = 0), alpha = 0.5) +
scale_y_discrete(expand = c(.01, 0)) +
scale_x_continuous(expand = c(0, 0), name = "water year total (taf) [difference]", sec.axis =
dup_axis(name = NULL)) +
theme_ridges(center = TRUE) + ggtitle("82 water year totals, difference from baseline") +
theme_gray() +
geom_point(data = df_md, mapping = aes(x = median, y = scen, color = dv), shape = 124, size = 10) +
geom_point(data = df_mn, mapping = aes(x = annmean, y = scen, fill = dv), color = "black", shape = 21)
}

Please briefly describe your problem and what output you expect. If you have a question, please don't use this form, but instead ask on the community forum http://community.plot.ly/c/api/r or stackoverflow http://stackoverflow.com.

Please include a minimal reprex. The goal of a reprex is to make it as easy as possible for me to recreate your problem so that I can fix it. If you've never heard of a reprex before, start by reading https://github.com/jennybc/reprex#what-is-a-reprex, and follow the advice further down the page. Do NOT include session info unless it's explicitly asked for, or you've used reprex::reprex(..., si = TRUE) to hide it away.

Delete these instructions once you have read them.


Brief description of the problem

# insert reprex here
@dbo99
Copy link
Author

dbo99 commented Jun 8, 2018

ggridges here's another from geom_ridgeline.

pr_ts_taf <- function(df, yrmin, yrmax, scalingfactor) { #plots monthly output on y, colors by annual total
df <-df %>% group_by(scen, wy) %>% mutate(wy_taf = sum(taf))
sc <- (max(df$taf) / min(df$taf) * scalingfactor) # usually needs to be very low, say 0.00005 for c9
minh <- min(df$taf)
yrmaxtitle <- yrmax-1
ggplot(df, aes(wm, wy, height = taf, group=as.factor(wy), fill = wy_taf))+
geom_ridgeline( stat = "identity", show.legend = T, scale = sc, alpha = 0.8,
min_height = minh) +
facet_grid(~scen) +
scale_fill_viridis() + theme_gray() +
scale_x_continuous(expand = c(0.02, 0.02),
breaks = c(1,2,3,4,5,6,7,8,9,10,11,12),
labels = c("O", "N", "D", "J", "F", "M", "A","M","J","J","A","S"),
sec.axis = dup_axis()) +
scale_y_continuous(expand = c(0.02, 0.02),
limits =c(yrmin,yrmax),
breaks = seq(from = 1922, to = 2002, by = 2),
labels = seq(from = 1922, to = 2002, by = 2),
sec.axis = dup_axis()) +
theme(axis.title.x = element_blank(), axis.title.y = element_blank())+
ggtitle(paste0(df$dv[1]," ", yrmin, " - ", yrmaxtitle))
}

@cpsievert
Copy link
Collaborator

Duplicate of #566. PR in progress #1087

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants