Тёмный

How to write our own theme in ggplot2 

Rajendra Choure
Подписаться 8 тыс.
Просмотров 556
50% 1

#ggplot2 #rprogramming #datavisualization #apa #plot
In this video i have demonstrated how to define your won theme using theme elements you defined for your best customized plot.
Its really easy. you just have to specify a function with theme name you want and in curly bracket of function just cut paste the theme elements from your best customized plot.
Now just as any predefined theme add this theme to your customized plot.
#code
library(ggplot2)
str(ToothGrowth)
ToothGrowth$dose = factor(ToothGrowth$dose)
apa theme
theme_apa = function(){
theme_classic()+
theme(
legend.background = element_rect(color="black"),
plot.title=element_text(family = "serif",size=14,face="bold"),
plot.subtitle=element_text(family = "serif",size=14, face="italic"),
axis.title = element_text(family = "serif",size=12, face="bold"),
plot.caption =element_text(hjust=0))
}
ggplot(ToothGrowth,aes(dose, len, fill=supp))+
geom_bar(stat="summary", fun="mean", position="dodge", width=0.6, color="gray60")+
stat_summary(geom="errorbar", fun.data=mean_se,position = position_dodge(width=0.6), width=0.2)+
scale_y_continuous(expand=c(0,0))+
scale_fill_manual(values=c("yellow","skyblue"))+
labs(title="Figure 1
", subtitle=" Effect of Vitamin C source on length of odontoblasts
",
caption="Note:The response is the length of odontoblasts (cells responsible for
tooth growth) in 60 guinea pigs. Each animal received one of three dose
levels of vitamin C (0.5, 1, and 2 mg/day)
by one of two delivery methods, orange juice or ascorbic
acid (a form of vitamin C and coded as VC). ", x="Dose", y="Length of Odontoblasts", fill="")+
theme_apa()
ggplot(ToothGrowth,aes(dose,len, fill=supp))+
geom_boxplot()+
labs(title="Figure 1
", subtitle=" Effect of Vitamin C source on length of odontoblasts
",
caption="Note:The response is the length of odontoblasts (cells responsible for
tooth growth) in 60 guinea pigs. Each animal received one of three dose
levels of vitamin C (0.5, 1, and 2 mg/day)
by one of two delivery methods, orange juice or ascorbic
acid (a form of vitamin C and coded as VC). ", x="Dose", y="Length of Odontoblasts", fill="")+
theme_apa()+
theme(legend.position=c(0.2, 0.85))
ggplot(iris,aes(Sepal.Length, fill=Species))+
geom_density(alpha=0.3)+
theme_apa()+
theme(legend.position=c(0.7, 0.85))
Facebook page:
/ rajendrachoureisc
Mail Id:
rajuchoure@gmail.com
youtube playlist:
• R programming tutorials

Опубликовано:

 

13 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 3   
Далее
How to create your own custom ggplot2 theme (CC152)
25:04
4 Year Sibling Difference! 😭 #shorts
00:11
Просмотров 11 млн
Advanced ggplot    (episode #1)
13:44
Просмотров 15 тыс.
Data Analysis and Visualizations using R
41:48
Просмотров 4,6 тыс.
Adding Themes to your ggplots in R
13:35
Просмотров 2 тыс.
Bar Charts using ggplot geom_bar - R Lesson 16
9:11
Просмотров 40 тыс.