3

When I run this programming code, I will get this error "ggfluctuation is deprecated. (Defunct; last used in version 0.9.1)". 1-How can i fix this issue? 2-In my original data set, I have two string variables with too many levels (first variable with 65 levels and second variable with 8 levels),can I have Heatmap table for these two variables although they have different number of levels? 3-What is the best way (plot) to show the relationship between these two categorical variables in my data set?

library(Hmisc)
library(ggplot2)
library(reshape)
data(HairEyeColor)
P=t(HairEyeColor[,,2])
Pm=melt(P)
ggfluctuation(Pm,type="heatmap")+geom_text(aes(label=Pm$value),colour="white")+ opts(axis.text.x=theme_text(size = 15),axis.text.y=theme_text(size = 15))
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
shadi
  • 73
  • 2
  • 10

2 Answers2

3

If you want to plot a heatmap just use geom_tile. Also, opts and theme_text are deprecated instead and have been replaced by theme and element_text respectively.

So, you could use this:

ggplot(Pm, aes(Eye, Hair, fill=value)) + geom_tile() +
  geom_text(aes(label=Pm$value),colour="white")+ 
  theme(axis.text.x=element_text(size = 15),axis.text.y=element_text(size = 15))

Which outputs:

enter image description here

Also, just to answer all the questions yes, ggplot can handle two categorical columns with a different number of levels and also a heatmap is a nice way to show the relationship between two categorical variables such as the ones you have.

LyzandeR
  • 37,047
  • 12
  • 77
  • 87
  • Great, Thanks so much for your help – shadi Dec 03 '15 at 00:57
  • Hi Again, just a question, when i run this code in my data set, i will get this error: Error: Aesthetics must either be length one, or the same length as the dataProblems:melt_table1$value . One of the variables has 13 and the other one has 8 levels. How can I fix this issue? – shadi Dec 03 '15 at 15:03
  • Hi. This is a data related issue, so it would be better to post a new question with a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) so that we can replicate your error and try to help you. – LyzandeR Dec 03 '15 at 15:07
1

The GGally package has a ggfluctuation2 function that replaces the deprecated ggfluctuation. But it's still pretty rough (you can't even specify axis labels) and I prefer the original ggplot function. You can also try ggally_ratio.

Mark R
  • 775
  • 1
  • 8
  • 23