I have a small issue, which I can ridiculously not solve myself.
I have a simple data frame, which I want to plot with ggplot2. When I use the variable weight as a factor I get all values in the x-axis, s. plot 2, but not when I use it as integer, s. plot 1. However, I want to use geom_smooth, which seems to function only with plot 1, but not in plot 2 where weight is a factor.
How do I get a graph in ggplot2, which shows me all values of weight and additionally the geom_smooth function?
Consider this example file:
require(ggplot2)
x <- get.url(https://dl.dropboxusercontent.com/u/109495328/example.csv)
app_df <- read.csv(x, header=T, sep = ",", quote = "", stringsAsFactors = FALSE, na.strings = "..")
colnames(app_df) <- c("Date", "Weight")
date <- as.Date(strptime(app_df$Date, "%d.%m.%Y"))
weight <- app_df$Weight
df <- na.omit(data.frame(date,weight))
# plot 1 (only few values indicated in x axis)
ggplot(df, aes(date,weight)) +
geom_point() +
geom_line(aes(group = "1")) +
geom_smooth(method = "lm")
# plot 2 (no smooth function)
ggplot(df, aes(date,as.factor(weight))) +
geom_point() +
geom_line(aes(group = "1")) +
geom_smooth(method = "lm")
geom_smooth). Also in the plot 2 you get 16 points but this plot is wrong because weight has to be used as integer and not the factor.scale_y_continuousto customize limits and breaks.scale_y_continousin the present example so that I get the same 16 data points in the x axis as in plot 2?