xxxxxxxxxx
%%r
options(bitmapType='cairo'); fn<-'Rplots.png'
png(fn,pointsize=12,bg='whitesmoke')
library(ggplot2)
theme_set(theme_bw())
g<-ggplot(mpg,aes(manufacturer))
g+geom_bar(aes(fill=class),width=.8)+
scale_fill_brewer(palette='BuPu')+
labs(title='Bar Charts for Categorical Variables')+
theme(axis.text.x=element_text(size=3,angle=65,vjust=.5),
axis.text.y=element_text(size=3,hjust=.5),
legend.text=element_text(size=3),
legend.key.size=unit(.3,'cm'),
title=element_text(size=5))
ggsave(fn,width=2.4,height=1.8)
dev.off()
xxxxxxxxxx
%%r
options(bitmapType='cairo'); fn<-'Rplots.png'
png(fn,pointsize=12,bg='whitesmoke')
library(ggplot2)
theme_set(theme_bw())
ggplot(economics,aes(x=date,y=psavert))+
geom_area(fill='steelblue',color='slategray',cex=.3,alpha=.7)+
labs(title='Personal Savings Rate',
x='date',y='personal savings rate')+
theme(axis.text.x=element_text(size=4,angle=15,vjust=.5),
axis.text.y=element_text(size=4,hjust=.5),
title=element_text(size=5,color='slategray'))
ggsave(fn,width=2.4,height=1.8)
dev.off()
xxxxxxxxxx
%%r
options(bitmapType='cairo'); fn<-'Rplots.png'
png(fn,pointsize=12,bg='whitesmoke')
library('MASS'); library(ggplot2)
theme_set(theme_bw())
data(Boston)
p<-ggplot(Boston,aes(x=c(medv)))+
geom_histogram(aes(y=..density..),binwidth=1,alpha=.2,
fill='slategray',color='royalblue')+
geom_density(alpha=.6,lw=1,fill='royalblue',color='slategray')+
labs(title='Distribution for `MEDV`',
x='indicator',y='density')+
theme(axis.text.x=element_text(size=4,vjust=.5),
axis.text.y=element_text(size=4,hjust=.5),
title=element_text(size=5,color='slategray'))
ggsave(fn,width=2.1,height=1.4)
dev.off(); summary(Boston)
xxxxxxxxxx
!curl -o chicago-nmmaps.csv https://raw.githubusercontent.com/onlyphantom/ggplot2cheatsheet/master/chicago-nmmaps.csv
xxxxxxxxxx
%%r
options(bitmapType='cairo'); fn<-'Rplots.png'
png(fn,pointsize=12,bg='whitesmoke')
library(ggplot2)
theme_set(theme_bw())
chic<-read.csv('chicago-nmmaps.csv')
chic$date<-as.Date(as.character(chic$date),'%Y-%m-%d')
g<-ggplot(chic,aes(x=date,y=temp,color=season,shape=season))
g+geom_point(size=.2)+
scale_color_brewer(palette='Set1')+
labs(x='year',y='temperature (°F)')+ggtitle('Chicago`s Daily Temperature')+
theme(axis.text.x=element_text(size=4,angle=30,vjust=.5),
axis.text.y=element_text(size=4,hjust=.5),
legend.text=element_text(size=4),legend.position='top',
title=element_text(size=4,color='slategray'))
ggsave(fn,width=2.4,height=2.4)
dev.off()
xxxxxxxxxx
%%r
options(bitmapType='cairo'); fn<-'Rplots.png'
png(fn,pointsize=12,bg='whitesmoke')
library(ggplot2)
theme_set(theme_bw())
chic<-read.csv('chicago-nmmaps.csv')
chic$date<-as.Date(as.character(chic$date),'%Y-%m-%d')
g<-ggplot(chic,aes(season,o3))+
geom_boxplot(aes(fill=season,color=season),size=.2,outlier.size=.2)+
labs(x='season',y='ozone')+ggtitle('Chicago`s Daily Ozone Levels')+
scale_color_brewer(palette='Set2')+
scale_fill_brewer(palette='Set1')+
theme(axis.text.x=element_text(size=4,angle=15,vjust=.5,family='Courier'),
axis.text.y=element_text(size=4,hjust=.5,family='Courier'),
legend.text=element_text(size=4,family='Courier'),
legend.position='top',legend.title=element_blank(),
legend.key.size=unit(.4,'cm'),
title=element_text(size=7,color='slategray',family='Comic Sans MS'))
ggsave(fn,width=2.4,height=1.8)
dev.off()
xxxxxxxxxx
%%r
# for your experiments