Violin plot Tutorial 1-Data Visualization using R and GGplot2, plotting data distribution
HTML-код
- Опубликовано: 21 авг 2024
- #Rprogramming #datavisualisation #ggplot #datanalysis #Datadistribution #Violin plot
This session demonstrates how to plot visulaise data distribution using ggplot2. Violin plot is discussed here. data sets used are iris, mpg and diamonds. data frame functions head(), str(), summary are also discussed.
following code is used in the tutorial.
You can copy paste the code in your script window but my suggestion will be type the code to learn it better.
#Datavisualization using ggplot2
#Basic Violin plot
ggplot(iris,aes(Species,Sepal.Length,fill=Species))+
geom_violin()
changing the theme of plot to make it look batter
ggplot(iris,aes(Species,Sepal.Length,fill=Species))+
geom_violin()+
theme_classic()
Still better theme ( This I havent explained in video)
ggplot(iris,aes(Species,Sepal.Length,fill=Species))+
geom_violin()+
theme_pubr()
You can add jittered points also to make it look better
ggplot(iris,aes(Species,Sepal.Length,fill=Species))+
geom_violin()+
geom_jitter()+
theme_pubr()
give color to points as per species( Map color to Species)
ggplot(iris,aes(Species,Sepal.Length,fill=Species))+
geom_violin()+
geom_jitter(aes(color=Species))+
theme_pubr()
Changing transperency using alpha argument of geom_violin to make points visible
ggplot(iris,aes(Species,Sepal.Length,fill=Species))+
geom_violin(alpha=0.3)+
geom_jitter(aes(color=Species))+
theme_pubr()
changing label of y axis as default is vector name.and adding title , subtitle and caption
I am not much carefull about the accuracy of labels
ggplot(iris,aes(Species,Sepal.Length,fill=Species))+
geom_violin(alpha=0.3)+
geom_jitter(aes(color=Species))+
theme_pubr()+
labs(title=" Violin Plot Demonstration",
y="Sepal Length( in mm)",
subtitle=" Iris flower -mesurement of flower
parts-petals and sepals", #
to give linebreak
caption="Data by Anderson")
rmoving the fill argument still make it better
ggplot(iris,aes(Species,Sepal.Length))+
geom_violin(alpha=0.3)+
geom_jitter(aes(color=Species))+
theme_pubr()+
labs(title=" Violin Plot Demonstration",
subtitle=" Iris flower -mesurement of flower
parts-petals and sepals", #
to give linebreak
caption="Data by Anderson")
Thats all for the violin plot. Still much is there.
I am unable to install ggplot2. It says 'package ‘ggplot2’ was built under R version 4.2.2'. My console is 4.2.1., I'm unable to update that to 4.2.2. I'm basically stuck and cannot go any further.
Shut down your rstudio. Search r programming download on Google. Download r programming. Install it ,
also download and install rstudio again. Start Rstudio.
Go to tools menu. Check for package updates . Select all and Update all the packages.
Now install ggplot2.
@@DevResearch Thank you sir. Its working now.
Can u pls provide the script for violin plot
Yes I will provide that in description.
Also if we are uploading the file rather than typing the data in it. Can I know the format of the data to plot violin plot