27

I'm working in a big farm as a statistician and my master asked me to draw something to remind him his childhood. It was not easy for me to do that, because there was one big restriction: to do everything using only R. That's how I did that. Could you be so kind and help me to draw better cow?

library(ggplot2)

sim=function(xy){
  xx=xy[,"x"]*(-1)
  yy=xy[,"y"]
  gg=xy[,"gr"]
  xy=rbind(xy,cbind(xx,yy,gg))
  return(as.data.frame(xy))
}

circleFun <- function(center = c(0,0),diameter = 1, npoints = 100){
  r = diameter / 2
  tt <- seq(0,2*pi,length.out = npoints)
  xx <- center[1] + r * cos(tt)
  yy <- center[2] + r * sin(tt)
  return(data.frame(x = xx, y = yy))
}

n=100 

akys <- circleFun(c(1,5),1.5,npoints = n)
akys=as.matrix(cbind(akys,gr=4))
akys=sim(akys)

akys21 <- circleFun(c(1,4.5),0.5,npoints = n)
akys21=as.matrix(cbind(akys21,gr=5))

akys22 <- circleFun(c(-1,5.3),0.7,npoints = n)
akys22=as.matrix(cbind(akys22,gr=5))

nosis=circleFun(c(0.6,1),0.6,npoints = n)
nosis=as.matrix(cbind(nosis,gr=6))
nosis=sim(nosis)

x=c(0,1,3,3,2,0,0,1,1,0,3,5,2)
y=c(0,0,4,6,7,7,0,0,2,2,6,10,7)
gr=c(2,2,2,2,2,2,3,3,3,3,1,1,1)
xy=cbind(x=x,y=y,gr=gr)

data=sim(xy)
data=rbind(data,akys,akys21,akys22,nosis)

ggplot()+geom_polygon(data=data,mapping=aes(x=x,y=y,fill=factor(gr),group=gr), linetype=0, colour="black")+theme_bw()+
  scale_fill_manual(values=c("cornsilk2","chocolate4","lightpink","white","black","maroon4"))+
  theme(axis.line=element_blank(),axis.ticks=element_blank(),axis.text=element_blank(),legend.position="none",panel.grid=element_blank(),panel.border=element_blank())+xlab("")+ylab("")+
  ggtitle("Crazy Cow Wishing You Happy Easter!!!")

enter image description here

12
  • 31
    You may have to butter us up a bit more to get this done. You shouldn't really be milking StackOverflow like this. Mooove on to something else, no bull next time.
    – Spacedman
    Mar 29, 2013 at 14:37
  • 25
    I'll ask the mods to move this to livestockoverflow.com
    – Spacedman
    Mar 29, 2013 at 14:38
  • 15
    This question is currently being discussed on meta
    – Rachel
    Mar 29, 2013 at 15:26
  • 5
    @SynergyParnu When you say "Help me to draw better cow?", do you mean a better-looking cow? A more complete cow instead of just the head? Or does "better" refer to something else, like code quality or performance?
    – Rachel
    Mar 29, 2013 at 15:53
  • 16
    @Spacedman: I think two highly-upvoted joke comments is enough. If you have absolutely nothing constructive to add to the question, please refrain.
    – BoltClock
    Mar 29, 2013 at 15:58

1 Answer 1

26

If you are on Linux and have cowsay installed the solution is fairly straightforward:

> system("cowsay I quit")
 ________
< I quit >
 --------
    \   ^__^
     \  (oo)\_______
        (__)\       )\/\
            ||----w |
            ||     ||
18
  • As I remember, cow can be male.
    – liuminzhao
    Mar 29, 2013 at 14:52
  • 7
    I believe a male cow is a bull. and I also believe this is awesome Mar 29, 2013 at 14:52
  • 12
    He wants a cow of the R breed, not Perl -_-
    – asheeshr
    Mar 29, 2013 at 15:37
  • 1
    @Rachel, the [ggplot2] tag
    – GSee
    Mar 29, 2013 at 15:53
  • 2
    @Arun sorry but I beg to differ with your differing. S was designed to easily pull in existing fortran code for example. If the solution was to arrange for a call to some fancy wizz-bang javascript dataviz code to do the drawing, no-one would be complaining and this would have far more than 18 up votes. And Drew does use R code... Mar 29, 2013 at 16:11

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.