Question: create a legend in ggplot2 plot
0
gravatar for Assa Yeroslaviz
4.5 years ago by
Assa Yeroslaviz1.2k
Munich
Assa Yeroslaviz1.2k wrote:

Hi,

 

I have a data.frame which I would like to plot using the ggplot2 package.

This is what i am doing:

myBreaks <- c(seq(0,0.001, 0.0002),seq(0.002,0.01,0.005), 0.01, seq(0.2,1,0.3), 2,5)#create the intervals

PlotData$bins <- findInterval(PlotData[,3],myBreaks) # plotting the braks

cols <- c('cadetblue1', 'cadetblue3', 'cadetblue4', 'cadetblue', 'burlywood', 'burlywood2', 'burlywood4', 'brown3', 'darkorchid4', 'darkorange2', 'darkolivegreen3', 'red3', 'midnightblue', 'chocolate2') # wanted colours

ggplot(PlotData, aes(y = start,  x = start.1)) + 
  labs(title = "normalized values") + 
  geom_tile(aes(fill = bins)) + 
  scale_fill_gradientn(name = "values", 
    breaks = myBreaks, 
    colours=cols, 
    labels = format(paste("\u2265", myBreaks,sep="")), 
    values= myBreaks, 
    rescaler = function(x, ...) x, 
    oob = identity, na.value="grey89", 
    guide="legend")

the plot I get shows all the colours in the plot itself but not in the legend. How can I convert the legend to also show all the colours as well as the breaks as  labels?

 

Thanks in advance

Assa

ggplot2 legend • 1.7k views
ADD COMMENTlink modified 4.5 years ago by Giovanni M Dall'Olio26k • written 4.5 years ago by Assa Yeroslaviz1.2k
1

Are you sure you posted the correct file? I can't see much in the plot you posted.

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

Yes I am. The file itself is not important. I dio have the corrct colours there.

 Yes i know there not many elements there, but this expected

i need to have the correct legend

 

ADD REPLYlink written 4.5 years ago by Assa Yeroslaviz1.2k
Please log in to add an answer.

Help
Access

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