Last active
October 25, 2020 20:19
-
-
Save kuang-da/c05e03d47513cbca7d715c663d7fb2cc to your computer and use it in GitHub Desktop.
[Notes about R] Common used code snippet for R programming #R #datascience
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
p <- ggplot() | |
p <- ggplot(data = k_suggest_df, | |
aes(x = k, y = median_kl, col = calc)) | |
p <- p + geom_line() | |
p <- p + xlab("K") | |
p <- p + ylab("Median KL divergence (across all cells)") | |
p <- p + theme_bw(base_size = 8) | |
#p <- p + theme(legend.key.size = unit(3, "line")) | |
p <- p + theme(legend.position = "bottom") | |
p <- p + theme(legend.title = element_blank()) | |
p <- p + theme(legend.margin=margin(0,0,0,0)) | |
p <- p + theme(legend.box.margin=margin(-10,0,0,0)) | |
print(p) |
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
library(dplyr) | |
df1 <- data.frame(x = 1:5, y = 2:6, z = 3:7) | |
rownames(df1) <- LETTERS[1:5] | |
df2 <- data.frame(x = 1:5, y = 2:6, z = 3:7) | |
rownames(df2) <- LETTERS[3:7] | |
# add rownames as a column in each data.frame and bind rows | |
bind_rows(df1 %>% tibble::rownames_to_column(), | |
df2 %>% tibble::rownames_to_column()) %>% | |
# evaluate following calls for each value in the rowname column | |
group_by(rowname) %>% | |
# add all non-grouping variables | |
summarise_all(sum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Input format