cuRve stitching

[This article was first published on You Know, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Remember curve stitching from grade school? It makes for a nice tutorial for working with some common R functionality.

Here’s an example of how to create the appearance of a parabola from plotting a series of straight lines:


pkg <- c("ggplot2","reshape2","RColorBrewer")
inst <- pkg %in% installed.packages()
if(length(pkg[!inst]) > 0) install.packages(pkg[!inst],repos=”http://cran.rstudio.com/”)
lapply(pkg,require,character.only=TRUE)
rm(list=c(“pkg”,”inst”))


n <- 50
m1 <- data.frame(x=c(rep(0,n),seq(n,1,-1)),
                 y=c(seq(1,n,1),rep(0,n)),
                 group=rep(seq(1,n,1),2))


p1 <- ggplot(data=m1,aes(x=x,y=y,group=group,color=factor(group))) + 
  scale_color_manual(values=rep(brewer.pal(8,”Dark2″),times=n*2)) + 
  geom_line(size=1.0) + 
  theme(legend.position=”none”,
        axis.title=element_blank(),
        panel.grid=element_blank(),
        axis.text=element_blank(),
        axis.ticks=element_blank())
p1





To leave a comment for the author, please follow the link and comment on their blog: You Know.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)