@Macux
2015-12-01T06:48:17.000000Z
字数 1271
阅读 1078
R语言_学习笔记
> p1 <- ggplot(faithful,aes(eruptions,waiting)) + geom_point(color="steelblue",shape=8)
> p1 + annotate("text",x=2.6,y=48,label="Group 1",family="font.serif",fontface="italic",
color="darkorange",size=7)
+ annotate("text",x=4.5,y=70,label="Group 2",family="font.serif",fontface="italic",
color="darkorange",size=7)
> p2 <- ggplot(data.frame(er=c(-3,3)),aes(er)) + stat_function(fun=dnorm,color="orange",size=1.3,
linetype=4) + labs(x="x")
> p2 + annotate("text",x=0,y=0.05,parse=TRUE,size=7,
label="'Function:' * y==frac(1,sqrt(2*pi)) * e^{-x^2/2}",color="steelblue")
> library(grid)
> p3 <- ggplot(subset(climate,Source=="Berkeley"),aes(Year,Anomaly10y))
+ geom_line(color="steelblue")
> p3 + annotate("segment",x=1827,xend=1820,y=-0.77,yend=-0.95,color="orange",size=2.2,
arrow=arrow())
+ annotate("segment",x=1950,xend=1980,y=-0.25,yend=-0.25,arrow=arrow(ends="both",
angle=90,lengt=unit(0.2,"cm")),size=2.3,color="orchid4")
+ annotate("rect",xmin=1870,xmax=1920,ymin=-1,ymax=1,alpha=0.5,fill="cornsilk")
> p4 <- ggplot(mpg,aes(displ,hwy)) + geom_point(size=3,shape=8,color="steelblue")
+ facet_grid(.~drv)
> fla <- data.frame(drv=c("4","f","r"),label=c("4wd","Front","Rear"))
> p4 + geom_text(x=6,y=40,aes(label=label),color="orange",fontface="bold",size=8,data=fla)