Question: (Closed) strange legend in ggplot
gravatar for tomasscheitel
4.6 years ago by
European Union
tomasscheitel20 wrote:



I am having difficulties plotting the correct values in my legend on a ggplot + geom_tile

the command I am using is:

ggplot(PlotData, aes(y = start,  x = start.1)) +  
   geom_tile(aes(fill = Substraction)) + 
   scale_size(range = c(1, 200)) + 
      colours = rainbow(100), 
      values = seq(0,1 , .1), 
      space = "Lab", 
      na.value = "white", 
      guide = "legend") + 
   ggsave(file=paste(PlotName, "_gplots1_1S.pdf", sep=""))

and the data I ' using as an input is a data.frame of dim 17766225x4, which looks line that:

       start start.1 Subtraction bins2
1_1001     1    1001     1.109193    12
1_2001     1    2001           NA    NA
1_3001     1    3001           NA    NA
1_4001     1    4001           NA    NA
1_5001     1    5001           NA    NA
1_6001     1    6001           NA    NA

I would like to show the values of Subtraction in my plot. The range of the data is [0,1].

But when I plot it, I get in my legend values between 0-25. I don't understand where this values are coming from.

Am I plotting the right values? What is happening to my scales?

a snapshot of the plot created with this command can be seen here.

thanks for any help,



ggplot legend • 1.7k views
ADD COMMENTlink modified 4.6 years ago by Giovanni M Dall'Olio26k • written 4.6 years ago by tomasscheitel20

I reformatted your code so that it is a bit easier to read. However this is really a question for stackexchange rather than biostar, because it is not related to bioinformatics. To force the scale limits just use limits=c(0,1) inside scale_fill. Check also if you have duplicated start / start.1 lines.

ADD REPLYlink modified 4.6 years ago • written 4.6 years ago by Giovanni M Dall'Olio26k

p.s. I think that the range in the legend may be due to duplicated start/start.1 lines. In this case geom_tile sums the values for all the duplicated values, in some cases summing up to 25. Try to run PlotData[duplicated(paste(PlotData$start, PlotData$start.1))] to find duplicated rows.

ADD REPLYlink written 4.6 years ago by Giovanni M Dall'Olio26k

Even your example has a value > 1, so your expected range seems to be off.

ADD REPLYlink written 4.6 years ago by Devon Ryan92k

thanks. That is true. I was using the too loosely.

I did !$Subtraction) - which gives only a logical vector (TRUE - FALSE || 0 -1), instead of calling the values themselves.

this is the real range:

[1] 6.532022e-06 2.512563e+01
ADD REPLYlink written 4.6 years ago by tomasscheitel20

Hello tomasscheitel!

We believe that this post does not fit the main topic of this site.

This is an R usage, not a bioinformatics-specific question, better suited to other forums.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.


ADD REPLYlink written 4.6 years ago by Neilfws48k
Please log in to add an answer.
The thread is closed. No new answers may be added.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2247 users visited in the last hour