[关闭]
@Macux 2015-12-01T06:48:17.000000Z 字数 1271 阅读 1077

R语言_ggplot2_Lv2_Annotation

R语言_学习笔记


  1. > p1 <- ggplot(faithful,aes(eruptions,waiting)) + geom_point(color="steelblue",shape=8)
  2. > p1 + annotate("text",x=2.6,y=48,label="Group 1",family="font.serif",fontface="italic",
  3. color="darkorange",size=7)
  4. + annotate("text",x=4.5,y=70,label="Group 2",family="font.serif",fontface="italic",
  5. color="darkorange",size=7)

此处输入图片的描述


  1. > p2 <- ggplot(data.frame(er=c(-3,3)),aes(er)) + stat_function(fun=dnorm,color="orange",size=1.3,
  2. linetype=4) + labs(x="x")
  3. > p2 + annotate("text",x=0,y=0.05,parse=TRUE,size=7,
  4. label="'Function:' * y==frac(1,sqrt(2*pi)) * e^{-x^2/2}",color="steelblue")

此处输入图片的描述


  1. > library(grid)
  2. > p3 <- ggplot(subset(climate,Source=="Berkeley"),aes(Year,Anomaly10y))
  3. + geom_line(color="steelblue")
  4. > p3 + annotate("segment",x=1827,xend=1820,y=-0.77,yend=-0.95,color="orange",size=2.2,
  5. arrow=arrow())
  6. + annotate("segment",x=1950,xend=1980,y=-0.25,yend=-0.25,arrow=arrow(ends="both",
  7. angle=90,lengt=unit(0.2,"cm")),size=2.3,color="orchid4")
  8. + annotate("rect",xmin=1870,xmax=1920,ymin=-1,ymax=1,alpha=0.5,fill="cornsilk")

此处输入图片的描述


  1. > p4 <- ggplot(mpg,aes(displ,hwy)) + geom_point(size=3,shape=8,color="steelblue")
  2. + facet_grid(.~drv)
  3. > fla <- data.frame(drv=c("4","f","r"),label=c("4wd","Front","Rear"))
  4. > p4 + geom_text(x=6,y=40,aes(label=label),color="orange",fontface="bold",size=8,data=fla)

此处输入图片的描述

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注