This tag is associated with 4 posts

ggplot2 in loops and multiple plots

# ggplot2 version
out <- NULL
p <- ggplot(data.frame(movieSummary), aes(y=movieSummary$Profit)) + ylab("Profits") + scale_y_continuous(labels=comma)
for(i in 2:(ncol(movieSummary)-1)) {
  p <- p + aes_string(x = names(movieSummary)[i]) + xlab(colnames(movieSummary[i])) + 
  out[[i]] <- p
  # ggsave(filename=paste("Plot of Profit versus",colnames(movieSummary[i]),".pdf",sep=" "), plot=p)
grid.arrange(out[[2]], out[[3]], out[[4]], out[[5]], out[[6]], out[[7]],
             out[[8]], nrow = 7)

Created by Pretty R at inside-R.org

Too tired to explain after so much debugging. But the key is at the line here

p + aes_string(x = names(mydata)[i])

Use aes_string instead of aes, so that when you look at summary(ggplot_obj), the mapping for x-values that are changing will be the actual string and not a variable i.

ggplot2 change y-axis label to non-scientific format

Below is a kmeans implementation, plotted with ggplot2. To change the y label values (because they are large, they are automatically formatted to scientific type i.e. exponential powers of n). To ‘unpower’ the values, you need to load the scales library and add the necessary in ggplot’s scale_y_continuous.

# K-Means Cluster Analysis
m <- mplayer    # matrix type
df <- player    # dataframe type
fit <- kmeans(m, 3)                          
aggregate(m,by=list(fit$cluster),FUN=mean)   # get cluster means

# Cluster graphing
df$cluster <- factor(fit$cluster)
centers <- as.data.frame(fit$centers)

library(scales)   # needed for formatting y-axis labels to non-scientific type
ggplot(data=df, aes(x=Experience, y=Career_salary, color=cluster )) + 
  geom_point() + scale_y_continuous(labels = comma) +
  geom_point(data=centers, aes(x=Experience, y=Career_salary, color='Center')) +
  geom_point(data=centers, aes(x=Experience, y=Career_salary, color='Center'), size=52, alpha=.3, show_guide=FALSE)

Plot three categorical variables and one continuous variable using ggplot2

Do something like this fromĀ http://www.r-bloggers.com/how-to-plot-three-categorical-variables-and-one-continuous-variable-using-ggplot2/

Overplotting solution for black-and-white graphics

Learn from http://val-systems.blogspot.sg/2012/06/overplotting-solution-for-black-and.html

Transform this

to this



Exploring and venting about quantitative issues

The Stone and the Shell

Using large digital libraries to advance literary history

Hi. I'm Hilary Mason.

Zoom out, zoom in, zoom out.

Introduction to Data Science, Columbia University

Blog to document and reflect on Columbia Data Science Class

statMethods blog

A Quick-R Companion

the Tarzan

[R] + applied economics.

4D Pie Charts

Scientific computing, data viz and general geekery, with examples in R and MATLAB.