I have a homework assignment where I need to make five different graphs for 3 different sets of data. I am using ggplot2 to make the graphs, Openxlsx to load the data, grid to create multigraph figures and RColorBrewer for additional color options. I tested all the graphs to make sure each one will give me a visible result, but when I load the grid.arrange line for the data from a bodyfat dataset I get the error:
Error: Continuous value supplied to discrete scale The code I wrote is as follows:
library(ggplot2)
library(openxlsx)
library(gridExtra)
library(grid)
library(RColorBrewer)
library(ggpubr)
bdyft <- read.xlsx("C:/Users/denge/Documents/School readings/Kepler_stats/BodyFat(John Rasp).xlsx", sheet = 1)
p1f <- ggplot(bdyft, aes(BODYFAT, ABDOMEN, color=ABDOMEN)) + geom_point()+labs(title="Bodyfat vs Size of Abdomen")#+scale_color_brewer(palette="Dark2")
ggplot(bdyft, aes(BODYFAT, ABDOMEN, color=ABDOMEN)) + geom_point()+labs(title="Bodyfat vs Size of Abdomen")#+scale_color_brewer(palette="Dark2")
p2f <- ggplot(data=bdyft, aes(AGE, y=ADIPOSITY, color=AGE)) + geom_bin2d(binwidth=c(1,2))+labs(title="Age Vs. Adiposity")
p3f <- ggplot(data = bdyft, aes(x=BODYFAT, y=DENSITY, color=BODYFAT)) + geom_count()+labs(title="Bodyfat vs Density")
p4f <- ggplot(data = bdyft, aes(x=DENSITY, y=HEIGHT)) + geom_smooth()+labs(title="Density vs. Height")
p5f <- ggplot(data = bdyft, aes(x=BODYFAT, y=AGE, z=HEIGHT, fill=HEIGHT))+geom_tile(width=1, height=2)+labs(title="Bodyfat vs. Age by Height")+scale_fill_gradientn(colours = rainbow(3))
plots <- grid.arrange(p1f, p2f, p3f, p4f, p5f)
ggsave(filename = "BodyFat_plots.pdf", plot = plots, device = "pdf")
I can't attach the data. The main issue I am having is that I don't know which graph needs discreet values.
thanks for the help.