Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Created January 6, 2021 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ram-N/df69157fa0f3b0989b0dc0d8540260c4 to your computer and use it in GitHub Desktop.
Save Ram-N/df69157fa0f3b0989b0dc0d8540260c4 to your computer and use it in GitHub Desktop.
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