Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Created Jan 6, 2021
Embed
What would you like to do?
pax_plot
plot_pax_wrap <- function(df, num_pax){
pax_rows <- round(sqrt(num_pax), -1)
pax_cols <- as.integer(num_pax/pax_rows)
df2 <- arrange(df, -Rev)
curr_pax <- 1
for (py in 1:pax_cols){
for (px in 1:pax_rows){
if (curr_pax <= num_pax){
df2[curr_pax, 'plot_col'] = px
df2[curr_pax, 'plot_row'] = py
curr_pax = curr_pax + 1
}
}
}
p <- ggplot(df2) + aes(x=plot_col, y=plot_row, color=Rev) +
geom_point(aes(shape=Cabin)) + scale_colour_gradient(
low = "red",
high = "green",
space = "Lab",
na.value = "grey50",
guide = "colourbar",
aesthetics = "colour"
)
return(p)
}
num_pax <- nrow(df)
plot_pax_wrap(df, num_pax)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment