Created
January 6, 2021 02:26
-
-
Save Ram-N/df69157fa0f3b0989b0dc0d8540260c4 to your computer and use it in GitHub Desktop.
pax_plot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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