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

*Related*

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 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...