create a legend in ggplot2 plot
0
0
Entering edit mode
7.1 years ago
Assa Yeroslaviz ★ 1.6k

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

ggplot(PlotData, aes(y = start,  x = start.1)) +
labs(title = "normalized values") +
geom_tile(aes(fill = bins)) +
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?

Assa

ggplot2 legend • 2.3k views
1
Entering edit mode

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

0
Entering edit mode

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