Last active
February 27, 2021 19:13
-
-
Save madilk/80bd1ac01bfb37eae74f69b2a7a3eb51 to your computer and use it in GitHub Desktop.
R GGplot - Combine Boxplot and Scatterplot into single visualization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create boxplot with data | |
boxplot <- ggplot(data,aes(x=channel, | |
y= revPerSessionUSD)) + | |
geom_boxplot()+ | |
ggtitle("Revenue Per Session - For Full Year") | |
#show viz | |
boxplot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Combine boxplot and jitter in R | |
boxjitterplot <- ggplot(data,aes(x=channel, | |
y= revPerSessionUSD)) + | |
geom_boxplot()+ylim(0,0.75)+ | |
geom_jitter(alpha=0.4)+ | |
ggtitle("Revenue Per Session - For Full Year") | |
boxjitterplot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#check if file loaded | |
channelData | |
#assigned name = data | |
data <- channelData | |
# install and load tidyverse | |
install.packages("tidyverse") | |
library(tidyverse) | |
#check summary stats in dplyr | |
data %>% | |
group_by(as.factor(channel)) %>% | |
summarize(min=min(revPerSessionUSD), | |
max=max(revPerSessionUSD), | |
mean=mean(revPerSessionUSD), | |
median=median(revPerSessionUSD), | |
IQRange=IQR(revPerSessionUSD)) | |
#create boxplot with data | |
boxplot <- ggplot(data,aes(x=channel, | |
y= revPerSessionUSD)) + | |
geom_boxplot()+ | |
ggtitle("Revenue Per Session - For Full Year") | |
#show viz | |
boxplot | |
#create scatterplot with data | |
scatterplot <- ggplot(data,aes(x=channel, | |
y= revPerSessionUSD)) + | |
geom_point()+ | |
ggtitle("Revenue Per Session - For Full Year") | |
#show viz | |
scatterplot | |
#create jitter plot with data | |
jitterplot <- ggplot(data,aes(x=channel, | |
y= revPerSessionUSD)) + | |
geom_jitter ()+ | |
ggtitle("Revenue Per Session - For Full Year") | |
#show viz | |
jitterplot | |
#create jitter plot with data, add alpha to show | |
#more concentration of points | |
jitterplot1 <- ggplot(data,aes(x=channel, | |
y= revPerSessionUSD)) + | |
geom_jitter (alpha=0.4)+ | |
ggtitle("Revenue Per Session - For Full Year") | |
#show viz | |
jitterplot1 | |
#Combine boxplot and jitter in R | |
boxjitterplot <- ggplot(data,aes(x=channel, | |
y= revPerSessionUSD)) + | |
geom_boxplot()+ylim(0,0.75)+ | |
geom_jitter(alpha=0.4)+ | |
ggtitle("Revenue Per Session - For Full Year") | |
boxjitterplot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create jitter plot with data, add alpha to show | |
#more concentration of points | |
jitterplot <- ggplot(data,aes(x=channel, | |
y= revPerSessionUSD)) + | |
geom_jitter (alpha=0.4)+ | |
ggtitle("Revenue Per Session - For Full Year") | |
#show viz | |
jitterplot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create scatterplot with data | |
scatterplot <- ggplot(data,aes(x=channel, | |
y= revPerSessionUSD)) + | |
geom_point()+ | |
ggtitle("Revenue Per Session - For Full Year") | |
#show viz | |
scatterplot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#check summary stats in dplyr | |
data %>% | |
group_by(as.factor(channel)) %>% | |
summarize(min=min(revPerSessionUSD), | |
max=max(revPerSessionUSD), | |
mean=mean(revPerSessionUSD), | |
median=median(revPerSessionUSD), | |
IQRange=IQR(revPerSessionUSD)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment