Mittwoch, 23. Oktober 2013

Scatterplot with histograms in R

What I want

What I type in R

What I get (and source)

I often want to visualizing 2 dimensional results.

require(stats)

plot(cars)

image

Scatter plots are nice, but it is nicer with histograms

library(psych)

data(sat.act)

scatter.hist(sat.act[5:6],pch=(19+sat.act$gender),col=c("blue","red")[sat.act$gender])

image

http://www.personality-project.org/r/psych/help/scatter.hist.html

R has serveral implementation sof that scatterplot /histogram combination

library(ade4)

data(rpjdl)

coa1 <- dudi.coa(rpjdl$fau, scannf = FALSE, nf = 4)

s.hist(coa1$li)

s.hist(coa1$li, cgrid = 2, cbr = 3, adj = 0.5, clab = 0)

s.hist(coa1$co, cgrid = 2, cbr = 3, adj = 0.5, clab = 0)

image

http://pbil.univ-lyon1.fr/ade4/ade4-html/s.hist.html

Or this implementation

http://www.r-bloggers.com/example-10-3-enhanced-scatterplot-with-marginal-histograms/

graph copied from http://www.r-bloggers.com/example-10-3-enhanced-scatterplot-with-marginal-histograms/


 

I have not yet made up my mind which to use…

1 Kommentar:

  1. The second one is more informative as it also correlates the y-axis of the histograms for both dimensions. However, the circles look a bit clumsy and I'm sure there is a more aesthetic solution to achieve the same

    AntwortenLöschen