#Lines
library(ggplot2)
ggplot(BOD, aes(x = Time, y = demand)) + geom_line()
BOD1 <- BOD
BOD1$Time <- factor(BOD1$Time)
BOD1$Time <-factor(BOD1$Time)
ggplot(BOD1, aes(x =Time, y =demand, group =1))+geom_line()
ggplot(BOD, aes(x = Time, y = demand)) + geom_line() + ylim(0, max(BOD$demand))
ggplot(BOD, aes(x = Time, y = demand)) + geom_line() + expand_limits(y =0)
ggplot(BOD, aes(x=Time, y = demand))+geom_line()+geom_point()
library(gcookbook)
str(worldpop)
## 'data.frame': 58 obs. of 2 variables:
## $ Year : int -10000 -9000 -8000 -7000 -6000 -5000 -4000 -3000 -2000 -1000 ...
## $ Population: int 2431 3564 5136 7562 11461 17920 28370 44820 72108 115066 ...
ggplot(worldpop, aes(x= Year, y = Population))+geom_line()+geom_point()
#install.packages("plyr")
library(plyr)
tg <- ddply(ToothGrowth,c("supp","dose"),summarise,length=mean(len))
ggplot(tg, aes(x= dose, y=length, color=supp))+geom_line()
ggplot(tg, aes(x=dose, y = length))+geom_line()
ggplot(tg, aes(x = dose, y = length,shape = supp))+geom_line()+geom_point(size=4)
ggplot(tg, aes(x = dose, y= length, shape = supp))+geom_line(position=position_dodge(0.2))+geom_point(position = position_dodge(0.2),size=4)
ggplot(tg, aes(x=dose, y = length, color=supp))+geom_line()+scale_color_brewer(palette="Set1")
ggplot(BOD, aes(x=Time, y=demand))+geom_line()+geom_point(size=4,shape=22,color="darkred",fill="pink")
ggplot(BOD, aes(x=Time, y= demand))+geom_line()+geom_point(size=4,shape=21,fill="white")
pd <- position_dodge(0.2)
ggplot(tg,aes(x=dose,y=length,fill=supp))+geom_line(position=pd)+geom_point(shape=21,size=3,position = pd)+scale_fill_manual(values=c("black","white"))
str(sunspot.year)
## Time-Series [1:289] from 1700 to 1988: 5 11 16 23 36 58 29 20 10 8 ...
sunspotyear <- data.frame(
Year = as.numeric(time(sunspot.year)),
Sunspots = as.numeric(sunspot.year)
)
ggplot(sunspotyear, aes(x=Year, y=Sunspots))+geom_area()
ggplot(sunspotyear, aes(x = Year, y = Sunspots))+geom_area(color="black",fill="blue",alpha=.2)
library(gcookbook)
ggplot(uspopage, aes(x=Year, y = Thousands, fill= AgeGroup))+geom_area()
uspopage_prop <- ddply(uspopage,"Year", transform,Percent=Thousands/sum(Thousands)*100)
ggplot(uspopage_prop, aes(x = Year, y = Percent, fill = AgeGroup))+geom_area(color="black", size=2, alpha=.4)+scale_fill_brewer(palette = "Blues",breaks=rev(levels(uspopage$AgeGroup)))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.