install.packages("ggplot2")
library(ggplot2)
Ns <- 100
Nv <- 4
r <- 4
df <- data.frame(v1 = sample(1:4, Ns, replace = TRUE))
df$v2 <- rnorm(Ns,sd=0.5) + df$v1
df$v3 <- sin(df$v2) + 2
df$v4 <- df$v2^2 + df$v3^3
str(df)
head(df)
hist(df$v2)
gp <- ggplot(data = df)
gp <- gp + aes(x = v2)
gp <- gp + geom_bar()
gp
f <- factor(df$v1)
gp <- ggplot(data = df)
gp <- gp + aes(x =v2, fill = f)
gp <- gp + geom_bar()
gp
gp <- ggplot(data = df)
gp <- gp + aes(x =v2, fill = f)
gp <- gp + geom_bar(position = "fill")
gp
gp <- ggplot(data = df)
gp <- gp + aes(x =v2, fill = f)
gp <- gp + geom_bar(position = "dodge")
gp
plot(df$v2, df$v3)
gp <- ggplot(data = df)
gp <- gp + aes(x = v2, y = v3)
gp <- gp + geom_point()
gp
f <- factor(df$v1)
gp <- ggplot(data = df)
gp <- gp + aes(x = v2, y = v3, colour = f)
gp <- gp + geom_point()
gp
gp <- ggplot(data = df)
gp <- gp + aes(x = v2, y = v3, colour = v4)
gp <- gp + geom_point()
gp
gp <- ggplot(data = df)
gp <- gp + aes(x = v2, y = v3, colour = v4)
gp <- gp + geom_point()
gp <- gp + scale_colour_gradient(low = "blue", high ="yellow")
gp
gp <- ggplot(data = df)
gp <- gp + aes(x = v2, y = v3, size = v4)
gp <- gp + geom_point()
gp
gp <- ggplot(data = df)
gp <- gp + aes(x = v2, y = v3, colour = v4)
gp <- gp + geom_point()
gp <- gp + scale_colour_gradient(low = "blue", high ="yellow")
gp <- gp + facet_wrap(~ v1)
gp
gp <- ggplot(data = df)
gp <- gp + aes(x = v1, y= v2)
gp <- gp + geom_point()
gp <- gp + geom_smooth(method = "lm")
gp
gp <- ggplot(data = df)
gp <- gp + aes(x = v2, y= v3)
gp <- gp + geom_point()
gp <- gp + geom_smooth(method = "lm")
gp
f <- factor(df$v1)
gp <- ggplot(data = df)
gp <- gp + aes(x = v2, y= v3, group = f)
gp <- gp + geom_point()
gp <- gp + geom_smooth(method = "lm")
gp
f <- factor(df$v1)
gp <- ggplot(data = df)
gp <- gp + aes(x = v2, y= v3, group = f, colour = f)
gp <- gp + geom_point()
gp <- gp + geom_smooth(method = "lm")
gp