Home > Software engineering >  Remove size label from ggplot
Remove size label from ggplot

Time:07-06

I created the following plot in R with the library ggplot2

p_cd = c(0.01,0.15,0.5,0.7,0.9)
p_cr = c(0.01,0.15,0.5,0.7,0.9)

data = as.data.frame(expand.grid(p_cd,p_cr))
data = cbind(data,rep(NA,dim(data)[1]))
colnames(data) = c('p_cd','p_cr','weights')
weights = runif(sum(seq(1,4,by=1)),0,5)
u = 1
for(i in 1:dim(data)[1]){
  if(data[i,1]>data[i,2]){
    data[i,3] = weights[u]
    u = u   1
  }
}

library(ggplot2)
ggplot(data[!is.na(data[,3]),], aes(x=p_cd, y=p_cr, color=weights, size = 3))  
  geom_point()

enter image description here

However, what I would like to do is to remove the label size from the plot, how can I do that?

CodePudding user response:

Add scale_size_continuous(guide = "none").

ggplot(data[!is.na(data[,3]),], aes(x=p_cd, y=p_cr, color=weights, size = 3))  
  geom_point()  
  scale_size_continuous(guide = "none")

enter image description here

Or ... if you want the legend but not the title, then

ggplot(data[!is.na(data[,3]),], aes(x=p_cd, y=p_cr, color=weights, size = 3))  
  geom_point()  
  scale_size_continuous(name = NULL)

enter image description here

CodePudding user response:

You should put size out of aes:

ggplot(data[!is.na(data[,3]),])  
  geom_point(aes(x=p_cd, y=p_cr, color=weights), size = 3)

  • Related