说在前面
很多人对科研的第一感觉就是枯燥、无聊,甚至还有点费头发。其实,科研有科研的乐趣,只需要你从中发现乐趣。今天,Immugent不讲难以理解的代码,也不讲枯燥无味的学术知识,来给大家介绍一个有趣的R包--ggdogs。
这个包的作者也是十分可爱的,想必生活中也是一个很有趣的人,他对画图神器ggplot2进行了一些改造,就能在图上画出各式各样的的狗子,快来have fun!
代码实现
那么先简单画个图来感受一下...
# install.packages("remotes")
# remotes::install_github("R-CoderDotCom/ggdogs@main")
library(ggdogs)
# install.packages("ggplot2")
library(ggplot2)
# Sample data
set.seed(1)
df <- data.frame(x = 1:10, y = rnorm(10))
# Plot
ggplot(df, aes(x = x, y = y)) +
geom_dog(size = 5)
图片
这个包还可以给画好的图加上狗子,并命名。
# Sample data
set.seed(1)
df <- data.frame(x = 1:10, y = rnorm(10))
# Plot
ggplot(df, aes(x = x, y = y)) +
geom_point(size = 3, color = 4) +
geom_dog(aes(x = 7, y = -0.5), dog = "thisisfine", size = 5) +
geom_label(aes(x = 7.75, y = -0.1, label = "This is fine"))
图片
当然,如果你想画多种狗子,也是可以实现的。
# Sample data
set.seed(1)
df <- data.frame(x = 1:10, y = rnorm(10),
dog = c(rep("husky", 5),
rep("gabe", 5)))
# Plot
ggplot(df, aes(x = x, y = y, dog = dog)) +
geom_dog(size = 5)
图片
那么最后来个狗子的全家福吧!!!
grid <- expand.grid(1:5, 3:1)
df <- data.frame(x = grid[, 1],
y = grid[, 2],
image = c("doge", "doge_strong", "chihuahua",
"eyes", "gabe", "glasses",
"tail", "surprised", "thisisfine",
"hearing", "pug", "ears",
"husky", "husky_2", "chilaquil"))
ggplot(df) +
geom_dog(aes(x, y, dog = image), size = 5) +
geom_text(aes(x, y - 0.5, label = image), size = 2.5) +
xlim(c(0.25, 5.5)) +
ylim(c(0.25, 3.5))
图片
说在最后
小编自己虽然科研也很忙,但还是会专门抽时间放松自己,生活科研两不误,这样才能更好的做出有价值的成果。最后,希望看到此贴的大家都能开开心心搞科研,早早发大paper!
网友评论