Drawing an excellent cow

0 votes

As a statistician employed by a sizable farm, my boss requested that I draw something to remind him of his youth. There was one major restriction that made it difficult for me to accomplish that: I could only use R for everything. That's how I went about it. Would you kindly assist me in improving my cow drawing?

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!!!")
Dec 25, 2022 in Others by Kithuzzz
• 38,000 points
389 views

1 answer to this question.

0 votes

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

> system("cowsay I quit")
 ________
< I quit >
 --------
    \   ^__^
     \  (oo)\_______
        (__)\       )\/\
            ||----w |
            ||     ||
answered Dec 25, 2022 by narikkadan
• 63,640 points

Related Questions In Others

0 votes
1 answer

Reducing sequences in an array of strings

I've written a C# app to solves ...READ MORE

answered Nov 2, 2018 in Others by DataKing99
• 8,250 points
902 views
0 votes
1 answer

How can you create an object in JavaScript?

JavaScript supports Object concept very well. You can create ...READ MORE

answered Mar 7, 2019 in Others by Frankie
• 9,830 points
574 views
0 votes
1 answer

How can you create an Array in JavaScript?

You can define arrays using the array literal as ...READ MORE

answered Mar 7, 2019 in Others by Frankie
• 9,830 points
623 views
0 votes
0 answers

how to list the contents of a asset into an event

May 29, 2019 in Others by anonymous
653 views
0 votes
1 answer

How to plot side-by-side Plots with ggplot2 in R?

By Using gridExtra library we can easily ...READ MORE

answered Apr 16, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by MD 8,825 views
+1 vote
1 answer

How to change fill color in each facet using ggplot2?

You can map the facetting variable to ...READ MORE

answered May 8, 2018 in Data Analytics by kappa3010
• 2,090 points
25,422 views
0 votes
11 answers

Changing the legend title in ggplot

Hi, you can also try guides() to ...READ MORE

answered Jul 30, 2019 in Data Analytics by Cherukuri
• 33,030 points
17,613 views
0 votes
1 answer

How to order bars in a bar graph using ggplot2?

The key to ordering is to set ...READ MORE

answered Jun 1, 2018 in Data Analytics by DataKing99
• 8,250 points
1,164 views
0 votes
1 answer

How to maximize SEO of an internationalized website?

there is no single answer to SEO ...READ MORE

answered Feb 11, 2022 in Others by narikkadan
• 63,640 points
532 views
0 votes
1 answer

Create an seo and web accessibility analyzer

there are some tools which  are already ...READ MORE

answered Feb 12, 2022 in Others by narikkadan
• 63,640 points
441 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP