I'm very new to the R language so please correct me if anything is wrong! I need to learn!
I've recently created a graph in RStudio using the ggplot2 package.
Now I have 2 questions.
Firstly, I am hugely interested in the data points behind the contour lines. Presumably in order to the programme to draw these lines there must be a series of underlying data points that allows the program to do so.
I am looking to explore whether it is possible to extract these data points?
Secondly if anyone could enlighten me on the underlying mathematical principals behind the +geom_density_2d() function in ggplot2 then that would be great!
The code I have used to create the graph is below...
ggplot(read.Alteryx("Office", mode="data.frame"),aes(x=Chances,y=Defensive,colour=Team)) +
facet_wrap( ~ Team, ncol=2) +
geom_density_2d() +
scale_colour_manual(values = c("Leicester City" = "#1b378b", "Tottenham Hotspur" = "#011657",
"Arsenal" = "#d02320", "Manchester City" = "#8ac7ff")) +
theme_bw() +
theme(panel.background=element_rect(fill="White")) +
theme(plot.background=element_rect(fill="White")) +
theme(panel.border=element_rect(colour="White")) +
theme(panel.grid.major=element_line(colour="gray48",size=0.2)) +
scale_x_continuous(minor_breaks=0, breaks=seq(14,26,12),limits=c(14,26)) +
scale_y_continuous(minor_breaks=0, breaks=seq(50,100,50),limits=c(50,100)) +
theme(axis.text.x=element_text(size=7,colour="#535353",face="bold")) +
theme(axis.text.y=element_text(size=7,colour="#535353",face="bold")) +
theme(axis.ticks=element_blank()) +
theme(legend.position="none") +
ggtitle("Pass completion % (Y) v Pass length M (X) for each game – EPL Top 4") +
theme(plot.title=element_text(face="bold",colour="#3C3C3C",size=10)) +
ylab("") +
xlab("") +
theme(axis.title.x=element_text(size=11,colour="#535353",face="bold",vjust=-.5)) +
geom_hline(yintercept=50,size=0.2,colour="gray48") +
geom_vline(xintercept=14,size=0.2,colour="gray48") +
theme(strip.text.x = element_text(size=0, face="bold"),
strip.background = element_rect(colour="White", fill="White")) +
geom_point(size = 3) +
theme(panel.margin = unit(3, "lines")) +
geom_rug(sides="trbl", size = 0.5)