0

I've tried to create an alpha plot but I couldn't find right way to do it. I tried different combination to figure out and I've almost there but I need a little help.
My question is how can I get rid off blue color in the plot.

My script is `

p <- ggplot(df, aes(x=x, y=y))
p + geom_hex(aes(alpha=..count..),bins=20)+
  scale_x_log10("ratio following/followers",
                labels = trans_format("log10", math_format(10^.x))) + 
  scale_y_log10("ratio messages received/sent", 
                labels = trans_format("log10", math_format(10^.x))) +
  theme_bw() + 
  theme(panel.background = element_blank(),
        panel.grid.major = element_blank(), panel.grid.minor=element_blank(),
        plot.background = element_blank())+ 
  #guides(fill=FALSE)+
  scale_alpha_continuous ("Counts",breaks=c(0,2000,4000,6000,8000,10000))+
  geom_vline(xintercept =1, color="red", size=0.25, linetype=5)+
  geom_hline(yintercept =1, color="red", size=0.25, linetype=5) +
  annotate('text', x=500, y=0.01, size=3, label="4\ncommon\nusers") +
  annotate('text', x=0.0001, y=0.01, size=3, label="3\nbroadcasters") +
  annotate('text', x=0.0001, y=7000, size=3, label="1\ninfluentials") +
  annotate('text', x=500, y=7000, size=3, label="2\nhidden\ninfluentials")

This script creates this plot

This scrip creates this plot

I can be able to get rid off blue legend with activating "guides(fill=FALSE)+" line in the script and it give this:

guides(fill=FALSE)+

You can reach sample data from here

Thanks @Didzis Elferts for his answer. I couldn't be sure about the legend and plot breaks colors. As you can see these pictures 10K and 8K has the same color (Am I right!) so 10K should be darker, shouldn't be. 10K 8K

eabanoz
  • 251
  • 3
  • 17
  • From your plots CHP and HDP it seems that you use different data. If that's true then maximal alpha value is assigned according to your actual data. – Didzis Elferts Dec 27 '16 at 15:33
  • You're right so in this case do I need to merge data or is there a way to fix it in the plot. – eabanoz Dec 27 '16 at 15:34
  • The easiest way would be to merge data and plot them using facets. Then you will have one legend for both groups – Didzis Elferts Dec 27 '16 at 15:49
  • @Didzis Elferts I knew how to merge list object into data frame with using one common column but in this data (it's list class) I don't have anything common such as date or user name so could you be able to advise me anything about it? – eabanoz Dec 27 '16 at 23:18
  • @Didzis Elferts I checked the length of list and all of them have different row number such as 6574, 4975, 5983, 6423 so it means that they can create empty row or repeat the values. – eabanoz Dec 27 '16 at 23:35
  • 1
    I guess that I figure out it. I created ID variable with using AKP$ID <-1:nrow(AKP) than merge data frames with (HDP,AKP,by="ID",all = TRUE). – eabanoz Dec 28 '16 at 03:56

1 Answers1

3

Function geom_hex() by default maps counts to the fill and so you get fill gradient (blue by default). If you just want map counts to alpha values then you must assign fill = outside the aes() of geom_hex() to some color (used grey45 as example). As fill = is set outside the aes() there won't be legend for fill values.

p + geom_hex(aes(alpha=..count..),bins=20, fill = "grey45")+ ...

enter image description here

Didzis Elferts
  • 95,661
  • 14
  • 264
  • 201
  • I actually used fill="#00000" out of aes but I couldn't be sure about breaks in legend color and plot color have the same color or not. – eabanoz Dec 27 '16 at 15:16
  • If you set `fill=` outside the `aes()` then your legend and plot will have the same breaks/values because all elements will have the same color (fill) and only alpha values will change (that coresponds to your legend) – Didzis Elferts Dec 27 '16 at 15:23
  • Thanks @Didzis Elferts. I've just updated the question to be more specific. I hope that I can make myself clear. – eabanoz Dec 27 '16 at 15:28