I first tried to run the first code provided in the assignment but I had issues with the visualization.
x <- 1967:1977
y <- c(0.5,1.8,4.6,5.3,5.3,5.7,5.4,5,5.5,6,5)
pdf(width=10, height=6)
plot(y ~ x, axes=F, xlab="", ylab="", pch=16, type="b")
axis(1, at=x, label=x, tick=F, family="serif")
axis(2, at=seq(1,6,1), label=sprintf("$%s", seq(300,400,20)), tick=F, las=2, family="serif")
abline(h=6,lty=2)
abline(h=5,lty=2)
text(max(x), min(y)*2.5,"Per capita\nbudget expanditures\nin constant dollars", adj=1,
family="serif")
text(max(x), max(y)/1.08, labels="5%", family="serif")
dev.off()
This is the code I used and it was not successful.
I also tried to run this code and received an error message while trying to load ggExtra package.
p <- ggplot(faithful, aes(waiting, eruptions)) + geom_point() + theme_tufte(ticks=F)
> ggMarginal(p, type = “histogram”, fill=”transparent”)
Error in ggMarginal(p, type = “histogram”, fill = “transparent”) :
could not find function “ggMarginal”
The command library(ggExtra) did not work for me and I had to search for the package and install it.
I was successful using this code.
library(ggplot2)
library(ggExtra)
library(ggthemes)
p <- ggplot(faithful, aes(waiting, eruptions)) + geom_point() + theme_tufte(ticks=F)
ggMarginal(p, type = "histogram", fill="transparent")
This is the visual I created.
Using marginal histogram scatterplot in ggPlot2










