you're reading...

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)


No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


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.