[R] R3.3.1 - Windows10 OS - Overriding default Legend title with user specified title

udhayakanth reddy udhay.mallela at gmail.com
Tue Jul 26 18:02:03 CEST 2016


Team - Could you please do the needful.

I have a below code using ggplot2() package. I am trying to plot between
the variables - 'Company Advertising' and 'Brand Revenue' of my data frame
'htmltable' , when the another variable 'Industry' is 'Luxury'; using
ggplot() function. I am using another variable of my data frame 'Brand
Value' as colour variable.

p<- ggplot(htmltable[htmltable$Industry='Luxury',],aes(x='CompanyAdvertising',y='BrandRevenue')

q <- p+geom_point(aes(color='BrandValue',size='BrandValue') +
geom_text(label='Brand')

r <- q+xlab("Company Advertisiment in Billions")+ylab("Brand Revenue
in Billions") +ggtitle("Luxury")

r+theme(plot.title=element_text(size=10,face='bold'),legend.key=element_rect(fill='light
blue'))

Here, I want to change my legend title from "BrandValue" to
"BrandValue in Billions". Please suggest.

I tried using labs parameter in the below statement. But it is
resulting in 2 legends.

r <- q+xlab("Company Advertisiment in Billions")+ylab("Brand Revenue
in Billions") +ggtitle("Luxury")+labs(colour="BrandValue in Billions")


Thanks,

Udhay

	[[alternative HTML version deleted]]



More information about the R-help mailing list