ggcharts 快速绘制优美图形
测试开头













测试结尾
一个努力中的公众号

1引言
ggcharts 基本 ggplot 的基础上,可以快速绘制出一些常见的图形,不用再一点一点代码进行调整,还是比较方便的。
github 地址:
https://github.com/thomas-neitmann/ggcharts

2安装
install.packages("ggcharts")
# or
if (!"remotes" %in% installed.packages()) {
install.packages("remotes")
}
remotes::install_github("thomas-neitmann/ggcharts", upgrade = "never")
如果从 github 上安装报错则运行下面代码再安装:
Sys.setenv(R_REMOTES_NO_ERRORS_FROM_WARNINGS = "true")
3介绍
ggplot 绘制分面条形图:
library(dplyr)
library(ggplot2)
library(ggcharts)
data("biomedicalrevenue")
biomedicalrevenue %>%
filter(year %in% c(2012, 2015, 2018)) %>%
group_by(year) %>%
top_n(10, revenue) %>%
ungroup() %>%
mutate(company = tidytext::reorder_within(company, revenue, year)) %>%
ggplot(aes(company, revenue)) +
geom_col() +
coord_flip() +
tidytext::scale_x_reordered() +
facet_wrap(vars(year), scales = "free_y")

使用 bar_chart 函数快速绘图:
biomedicalrevenue %>%
filter(year %in% c(2012, 2015, 2018)) %>%
bar_chart(x = company, y = revenue, facet = year, top_n = 10)
4不同图形示例
折线图
data("revenue_wide")
line_chart(data = revenue_wide, x = year, y = Roche:Bayer) +
labs(x = "Year", y = "Revenue (Billion USD)")

棒棒糖图
biomedicalrevenue %>%
filter(year == 2018) %>%
lollipop_chart(x = company, y = revenue, threshold = 30) +
labs(
x = NULL,
y = "Revenue",
title = "Biomedical Companies with Revenue > $30Bn."
) +
scale_y_continuous(
labels = function(x) paste0("$", x, "Bn."),
expand = expansion(mult = c(0, .05))
)

哑铃图
data("popeurope")
dumbbell_chart(
data = popeurope,
x = country,
y1 = pop1952,
y2 = pop2007,
top_n = 10,
point_colors = c("lightgray", "#494F5C")
) +
labs(
x = NULL,
y = "Population",
title = "Europe's Largest Countries by Population in 2007"
) +
scale_y_continuous(
limits = c(0, NA),
labels = function(x) paste(x, "Mn.")
)

diverging bar
data(mtcars)
mtcars_z <- dplyr::transmute(
.data = mtcars,
model = row.names(mtcars),
hpz = scale(hp)
)
diverging_bar_chart(data = mtcars_z, x = model, y = hpz)

diverging lollipop
diverging_lollipop_chart(
data = mtcars_z,
x = model,
y = hpz,
lollipop_colors = c("#006400", "#b32134"),
text_color = c("#006400", "#b32134")
)

金字塔图
data("popch")
pyramid_chart(data = popch, x = age, y = pop, group = sex)

不同主题
ggcharts_set_theme("theme_hermit")
bar_chart(data = diamonds, x = cut)

ggcharts_set_theme("theme_ng")
bar_chart(data = diamonds, x = cut)

ggcharts_set_theme("theme_nightblue")
bar_chart(data = diamonds, x = cut)


欢迎加入生信交流群。加我微信我也拉你进 微信群聊 老俊俊生信交流群
哦,数据代码已上传至QQ群,欢迎加入下载。
群二维码:
老俊俊微信:
知识星球:
所以今天你学习了吗?
欢迎小伙伴留言评论!
今天的分享就到这里了,敬请期待下一篇!
最后欢迎大家分享转发,您的点赞是对我的鼓励和肯定!
如果觉得对您帮助很大,赏杯快乐水喝喝吧!
往期回顾
◀组会文献分享 — YTHDF2 加速 UBXN1 mRNA 的降解促进胶质瘤的恶性进展
◀python 提取基因非冗余 exon-5UTR-CDS-3UTR 长度
◀python bioinfokit 计算 FPKM/RPKM/TPM 值
◀...
请关注“恒诺新知”微信公众号,感谢“R语言“,”数据那些事儿“,”老俊俊的生信笔记“,”冷🈚️思“,“珞珈R”,“生信星球”的支持!