Created
October 31, 2018 07:59
-
-
Save k-hench/6df1584eda5d23549d1be80fea267c54 to your computer and use it in GitHub Desktop.
rotating a ggplot obect
This file contains 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
library(tidyverse) | |
library(grid) | |
raw <- tibble(x = letters[1:5], y = x) | |
filter <- function(x, y) x <= y | |
data_tri <- purrr::cross_df(raw,.filter = filter) %>% mutate(val = rnorm(length(.$x))) | |
plot_tri <- ggplot(data = data_tri, aes(x = x, y = y, fill = val)) + | |
coord_equal()+ | |
geom_tile() + | |
theme_void() + | |
theme(legend.position = 'none') | |
data_box <- tibble(x = rep(letters[1:5], each = 5 ), y = rep((1:5)/5, each = 5)+rnorm(25)) | |
plot_box <- ggplot(data = data_box, aes(x=x,y=y))+ | |
geom_boxplot() | |
plot_tri_grob <- ggplotGrob(plot_tri) | |
plot_tri_rot <- editGrob(plot_tri_grob, vp=viewport(x=0.5, y=0.75, angle=-45,width = .7), name="tri") | |
cowplot::ggdraw(plot_tri_rot)+ | |
cowplot::draw_plot(plot_box,0,.04,.45,.21) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment