visualization

Generating PDF graphs

No votes yet

Creating a PDF version of your graphs is very easy:

pdfname<-paste("myfilename",".pdf",sep="")
pdf(pdfname, height=6.4,width=6.4)
# Plotting code
dev.off()

More than one series in plot

No votes yet

From the r-help mailing list:

x <- rnorm(10)
y <- runif(10)
z <- 1:10

plot(x~z, ylim=range(x, y), type='l') lines(y, col='red')

Customize plot axes

No votes yet

If you're not happy with what R puts on the axes of your plot (tickmarks, labels etc), plot with "axes=F", then add custom axes with the "axis()" function.

Read more

Grid behind plot

No votes yet

You have a plot, and you want to draw a grid behind it. If you add the grid to the plot, using either

grid()
or
abline()
, the lines will be added on top of your plot, not behind it. I found the solution on the R-help mailing list, here. Redraw the plot after adding the grid, but first set
par(new=T)
so that it will be drawn on top of the old plot on the same device.

Read more

Stem-and-leaf plots

No votes yet

However ironic it may be, we'll use the Iris data set as an example.

Read more

Simple k-means cluster analysis and plot

No votes yet

We know that the iris data set include three species. K-means does a pretty good job of correctly identifying correct groups.

data(iris)
cl <- kmeans(iris[,1:4], 3)
cl$cluster
cbind(1:150,iris$Species)

cl$cluster reveals which group each observation was placed in; compare this with a listing of the species designations mapped next to 150 index values (cbind(1:150,iris$Species)).

Read more

Density curve plotted over a histogram

No votes yet

Sometimes it's useful to plot a density curve over a histogram to help identify the distribution, or demonstrate the deviation between sample distributions and proposed population distributions:

data <- rnorm(1000)
hist(data, freq=FALSE)
curve(dnorm, add=TRUE)

Read more

Gradient under a curve

No votes yet

This question was posed on the R-help mailing list: I would like to fill the area under a curve with a gradient of colors. Are there any packages or trick I could use?

Vladimir recommended the poster to look at the following link:

http://www.stat.auckland.ac.nz/~ihaka/Graphics/index.html

describing what Ross Ihaka, co-founder of R, has been up to of late relating to R. He's using gradients to create "really snazzy presentation graphics".

However, being an EDA snob, I have a bit of a problem with this.

Read more

Adding a boxplot to a histogram

No votes yet

This person wondered if it was possible to add a small boxplot in a histogram, like where the legend might be.

Read more

Syndicate content