Skip to content

Instantly share code, notes, and snippets.

@madilk
Last active February 27, 2021 19:13
Show Gist options
  • Save madilk/80bd1ac01bfb37eae74f69b2a7a3eb51 to your computer and use it in GitHub Desktop.
Save madilk/80bd1ac01bfb37eae74f69b2a7a3eb51 to your computer and use it in GitHub Desktop.
R GGplot - Combine Boxplot and Scatterplot into single visualization
#create boxplot with data
boxplot <- ggplot(data,aes(x=channel,
y= revPerSessionUSD)) +
geom_boxplot()+
ggtitle("Revenue Per Session - For Full Year")
#show viz
boxplot
#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
#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
#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
#create scatterplot with data
scatterplot <- ggplot(data,aes(x=channel,
y= revPerSessionUSD)) +
geom_point()+
ggtitle("Revenue Per Session - For Full Year")
#show viz
scatterplot
#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