MCA - Multiple Correspondence Analysis example (MCA) graphic in ggplot

514 views
Skip to first unread message

edinhoestat

unread,
Feb 25, 2015, 11:56:08 AM2/25/15
to ggp...@googlegroups.com
Dear friends, it is a pleasure to join me in this group. I'm using a Multiple Correspondence Analysis example (MCA). Question:
  How do I change the font size in the chart (not the font size of the titles axes), but to the variables labels size.

Below the script:

#Usando MCA
# load packages
require(FactoMineR)
require(ggplot2)

# load data tea
data(tea)
tea
names(tea)
# select these columns
newtea = tea[, c("Tea", "How", "how", "sugar", "where", "always")]
newtea
# take a peek
head(newtea)
names(newtea)
str(newtea)
cats = apply(newtea, 2, function(x) nlevels(as.factor(x)))
cats

# apply MCA
mca1 = MCA(newtea, graph = FALSE)

# list of results
mca1

# table of eigenvalues
mca1$eig

#We can use the package "ggplot2()" to get a nice plot:
# data frame with variable coordinates
mca1_vars_df = data.frame(mca1$var$coord, Variable = rep(names(cats), cats))

# data frame with observation coordinates
mca1_obs_df = data.frame(mca1$ind$coord)



# plot of variable categories
g1<-ggplot(data=mca1_vars_df,
       aes(x = Dim.1, y = Dim.2, label = rownames(mca1_vars_df))) +
 geom_hline(yintercept = 0, colour = "gray70") +
 geom_vline(xintercept = 0, colour = "gray70") +
 geom_text(aes(colour=Variable)) +
 ggtitle("MCA plot of variables using R package FactoMineR")


g1 + theme(axis.title.x = element_text(face="bold", colour="#990000", size=30),
           axis.text.x  = element_text(angle=90, vjust=0.5, size=10))

# MCA plot of observations and categories
ggplot(data = mca1_obs_df, aes(x = Dim.1, y = Dim.2)) +
  geom_hline(yintercept = 0, colour = "gray70") +
  geom_vline(xintercept = 0, colour = "gray70") +
  geom_point(colour = "gray50", alpha = 0.7) +
  geom_density2d(colour = "gray80") +
  geom_text(data = mca1_vars_df,
            aes(x = Dim.1, y = Dim.2,
                label = rownames(mca1_vars_df), colour = Variable)) +
  ggtitle("MCA plot of variables using R package FactoMineR") +
  scale_colour_discrete(name = "Variable")

I live in Amazonas-Brasil.

Thanks.

Edson Lira
Statistical

adam.l...@pnc.com

unread,
Feb 25, 2015, 3:36:59 PM2/25/15
to edinhoestat, ggp...@googlegroups.com
Hi,

All you need is to specify a "size" argument in the geom_text call:

g1<-ggplot(data=mca1_vars_df,
       aes(x = Dim.1, y = Dim.2, label = rownames(mca1_vars_df))) +
 geom_hline(yintercept = 0, colour = "gray70") +
 geom_vline(xintercept = 0, colour = "gray70") +
 geom_text(aes(colour=Variable),size=3) +

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example:
https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options:
http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
ggplot2+u...@googlegroups.com.
For more options, visit
https://groups.google.com/d/optout.


The contents of this email are the property of PNC. If it was not addressed to you, you have no legal right to read it. If you think you received it in error, please notify the sender. Do not forward or copy without permission of the sender. This message may be considered a commercial electronic message under Canadian law or this message may contain an advertisement of a product or service and thus may constitute a commercial electronic mail message under US law. You may unsubscribe at any time from receiving commercial electronic messages from PNC at http://pages.e.pnc.com/globalunsub/
PNC, 249 Fifth Avenue, Pittsburgh, PA 15222; pnc.com

Reply all
Reply to author
Forward
0 new messages