user3089803
user3089803

Reputation: 109

ggplot boxplot with geom_jitter legend title

I am trying to create a box-plot with data points via geom_jitter. I cant find a way to change to legend title for the variable "clin" used to color the data points.

p<-ggplot(plot1, aes(culture, score,fill=group))
p+geom_boxplot()+ggtitle("title")+
ylab("y")+ xlab("x")+
guides(fill=guide_legend(title="In-vitro response"))+
scale_fill_grey(start = 0.6, end = 1)+
geom_jitter(aes(colour = clin), alpha=0.4) 

Data:

score group culture clin
1   a   co  y
3   a   co  y
7   a   co  y
5   a   co  y
5   a   co  y
5   b   co  y
6   b   co  y
9   b   co  n
7   b   co  n
8   b   co  n
6   b   co  n
9   b   co  n
9   a   mon y
9   a   mon y
6   a   mon y
6   a   mon n
5   a   mon y
4   b   mon y
4   b   mon y
3   b   mon n
3   a   mon n
3   b   mon n
3   b   mon n
3   b   mon n

NEED TO CHANGE TITLE FOR SECOND LEGEND: "CLIN"

Upvotes: 3

Views: 4673

Answers (1)

Ananta
Ananta

Reputation: 3711

Just have your all labels within lab, no need for separate xlab, yalab, title etc

 p=ggplot(df, aes(culture, score, fill=group))
 p+geom_boxplot()+
 scale_fill_grey(start = 0.6, end = 1)+
 geom_jitter(aes(colour = clin), alpha=0.4) +
 labs(title="TITLE",x="x", y="y", fill="In vitro", colour="C LIN")

Upvotes: 4

Related Questions