Fun with R graphics: A raptor and a cake

November 15, 2012
By

(This article was first published on Fiddling with data and code » R, and kindly contributed to R-bloggers)

I like to explore the graphics features of R.  Base graphics, ggplot2 are my favourites. On  other graphics packages, I haven’t used plotrix much. I am currently exploring grid package.

Raptor

First one is using ggplot2. (you could also do this using base graphics).

##
##reading raptor cordinates
rapt = read.csv("http://vinux.in/viz/misc/raptor.csv")
library(ggplot2)
ggplot(data=rapt) + 
  geom_polygon(aes(x=V1, y=V2, group=group), colour=I("gray") ) + 
  theme_bw() + 
  scale_x_continuous(limits = c(0, 400)) +   
  scale_y_continuous(limits = c(0, 250)) +
  geom_text(aes(100,230, label="Velociraptor"))+
  theme(axis.line=element_blank(), 
       axis.text.x=element_blank(),  
       axis.text.y=element_blank(), 
       axis.ticks=element_blank(), 
       axis.title.x=element_blank(),    
       axis.title.y=element_blank(), 
       legend.position="none", 
       panel.background=element_blank(), 
       panel.border=element_blank(), 
       panel.grid.major=element_blank(), 
       panel.grid.minor=element_blank(), 
       plot.background=element_blank())

It would be more fun if we can do animation on raptors. You can find animated version of raptor here. Rcode.

Cake

Here is the easy one. This one is a cake using plotrix package.

 

##
library(plotrix)
candle = function(pos)
{
x=pos[1]
y=pos[2]
rect(x,y,x+.2,y+2,col="red")
#  polygon(c(x-.2,x+.4,x+.1,x-.2), c(y+2,y+2,y+2.4,y+2),col="orange")
polygon(c(x+.05,x-.1,x+.1,x+.3,x+.15,x+0.05), c(y+2,y+2.3,y+2.6,y+2.3,y+2,y+2),col="orange")

}

cake_colour="#FF3399"
plot(c(0,10), c(0,10),type="n", bty="n",xaxt="n",yaxt="n", main="Cake", xlab="",ylab="")
draw.ellipse(5,2,col=cake_colour,a=4.4,b=1.7,border=1)
draw.ellipse(5,2,col=cake_colour,a=4,b=1.4,border=1)
rect(1,2,9,5,col=cake_colour,border=cake_colour)
lines(c(1,1),c(2,5))
lines(c(9,9),c(2,5))
draw.ellipse(5,5,col=cake_colour,a=4,b=1.4)

candle(c(2.5,4.5))
candle(c(3,5))
candle(c(4,4.5))
candle(c(5,5))
candle(c(6,4.5))
candle(c(7,5.2))

I have already discussed this graphs in my favourite forum talkstats.  I dedicated both the graphs to my friends in the forum. You can find more fun graphs in this forum.

 

The post Fun with R graphics: A raptor and a cake appeared first on Fiddling with data and code.

To leave a comment for the author, please follow the link and comment on their blog: Fiddling with data and code » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Dommino data lab

Quantide: statistical consulting and training



http://www.eoda.de







ODSC

ODSC

CRC R books series





Six Sigma Online Training





Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)