I have an assignment for my course and I need to make a ggplot with the txhousing data set but it doesn't work out for me, I keep on getting errors or no outcome. This is the exercise:
This is a scatterplot of sales and month
Insert a new r chunk that makes this plot
Use the function ggplot() (check the help file for this function)
As data argument use na.omit(txhousing)
In the aes argument put month on the x-axis and log(sales) on the y-axis
Use geom_point to produce a line
Once the r chunk runs fine, copy it and
Add aes(color=year) to the geom.
Copy the latest r chunk, and add the geom_smooth to the plot
I've tried changing the ggplot coding multiple times but I don't come any further than a simple dot in the middle of a graph. Because the ggplot won't even work yet when I try the geom_point , I haven't added geom_smooth yet either
library(tidyverse)
summary(txhousing)
na.omit(txhousing)
txhousing<- as.data.frame(txhousing)
txhousing %>% mutate(logsales= log(txhousing$sales))
ggplot(na.omit(txhousing), aes("month", "logsales")) +
geom_point(aes(color=year))
I expect to get a scatterplot of the logsales
and month from the txhousing
data but what I get so far is a graph with the names of the variables on the axis, but further it's a blue dot in the origin of the graph and a legend which says what color stands for what year.