說在前面
很多人對科研的第一感覺就是枯燥、無聊透硝,甚至還有點費頭發(fā)狰闪。其實,科研有科研的樂趣濒生,只需要你從中發(fā)現(xiàn)樂趣埋泵。今天,Immugent不講難以理解的代碼,也不講枯燥無味的學(xué)術(shù)知識丽声,來給大家介紹一個有趣的R包--ggdogs礁蔗。
這個包的作者也是十分可愛的,想必生活中也是一個很有趣的人雁社,他對畫圖神器ggplot2進(jìn)行了一些改造浴井,就能在圖上畫出各式各樣的的狗子,快來have fun!
代碼實現(xiàn)
那么先簡單畫個圖來感受一下...
# 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"))
當(dāng)然,如果你想畫多種狗子徒坡,也是可以實現(xiàn)的撕氧。
# 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))
說在最后
小編自己雖然科研也很忙,但還是會專門抽時間放松自己锦溪,生活科研兩不誤不脯,這樣才能更好的做出有價值的成果。最后刻诊,希望看到此貼的大家都能開開心心搞科研跨新,早早發(fā)大paper!