Merry Christmas

25. December 2016 | categories: R GNU

In the open source statistics program R you can not only display statistics, but you can also draw any object with it. The following code is used to draw a Christmas tree. I wish you a Merry Christmas and a Happy New Year.

library(ggplot2)

ggplot(data.frame(x=1:6,y=1:6),aes(x=x,y=y)) + 
  geom_rect(xmin=4.8,xmax=5.2,ymin=0.5,ymax=1.5,fill="saddle brown") +
  geom_polygon(x=c(4.8,4.5,4.6,5.4,5.5,5.2),y=c(1.2,1.3,0.45,0.45,1.3,1.2),fill="#173B0B") +
  geom_polygon(x=c(2.4,4.8,5,5.2,7.6,5),y=c(rep(1.5,5),3),fill="#088A29") +
  geom_polygon(x=c(2.7,4.8,5,5.2,7.3,5),y=c(rep(2.4,5),3.9),fill="#0B6121") +
  geom_polygon(x=c(3,4.8,5,5.2,7,5),y=c(rep(3.3,5),4.8),fill="#088A29") +
  geom_polygon(x=c(3.3,4.8,5,5.2,6.7,5),y=c(rep(4.2,5),5.7),fill="#0B6121") +
  geom_polygon(x=c(3.6,4.8,5,5.2,6.4,5),y=c(rep(5.1,5),6.6),fill="#088A29") +
  geom_polygon(x=c(4.7,4.8,4.9,5,5.3,5),y=c(rep(6.7,5),7.1),fill="gold") +
  geom_polygon(x=c(4.7,4.8,4.9,5,5.3,5),y=c(rep(6.98,5),6.58),fill="gold") +
  geom_point(col="#c0c0c0",x=c(4.7,4.3,5.4,4.7,4.8,5.8),y=c(1.8,4.7,3.2,6,4.2,2.3),size=7) +
  geom_point(col="gold",x=c(3,4.2,6.5,5.5,4.1,5.7),y=c(1.5,2.5,1.7,5.7,3.7,4.8),size=7) +
  geom_rect(xmin=2.8,xmax=2.9,ymin=2.4,ymax=2.8, fill="red") +
    geom_rect(xmin=2.84,xmax=2.86,ymin=2.8,ymax=2.9,fill="grey") +
  geom_rect(xmin=7.1,xmax=7.2,ymin=2.4,ymax=2.8, fill="red") +
    geom_rect(xmin=7.14,xmax=7.16,ymin=2.8,ymax=2.9,fill="grey") +
  geom_rect(xmin=3.1,xmax=3.2,ymin=3.3,ymax=3.7, fill="red") +
    geom_rect(xmin=3.14,xmax=3.16,ymin=3.7,ymax=3.8,fill="grey") +
  geom_rect(xmin=6.8,xmax=6.9,ymin=3.3,ymax=3.7, fill="red") +
    geom_rect(xmin=6.84,xmax=6.86,ymin=3.7,ymax=3.8,fill="grey") +
  geom_rect(xmin=3.4,xmax=3.5,ymin=4.2,ymax=4.6, fill="red") +
    geom_rect(xmin=3.44,xmax=3.46,ymin=4.6,ymax=4.7,fill="grey") +
  geom_rect(xmin=6.5,xmax=6.6,ymin=4.2,ymax=4.6, fill="red") +
    geom_rect(xmin=6.54,xmax=6.56,ymin=4.6,ymax=4.7,fill="grey") +
  theme_classic() + ylim(0,8) + xlim(1,9) + ylab("") + xlab("") +
  theme(axis.line=element_blank(),axis.text=element_blank(),axis.ticks = element_blank())