ggplot2 - Matrix of Histograms Using ggplot in R -


i newbie @ r, , have been trying use 'attitude' dataset create histograms each of columns.

i can achieve manually typing out:

par(mfrow=c(1,7)) hist(attitude$rating) hist(attitude$complaints) hist(attitude$privileges) hist(attitude$learning) hist(attitude$raises) hist(attitude$critical) hist(attitude$advance)

however, i'd use single function plot histograms, possibly using ggplot. command used after searching on stackoverflow:

ggplot(attitude, aes(x=variable)) + geom_histogram()

but seems i'm doing wrong since message:

error in eval(expr, envir, enclos) : object 'variable' not found

i appreciate pointers in regard. thank you.

you need convert attitude data long data format first - e.g., using melt reshape2:

attitudem <- melt(attitude) 

then can facet ggplot variable , automatically create separate histograms each dimension.

g <- ggplot(attitudem,aes(x=value)) g <- g + geom_histogram() g <- g + facet_wrap(~variable) g 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -