udhayakanth reddy
2016-Jul-26 16:02 UTC
[R] R3.3.1 - Windows10 OS - Overriding default Legend title with user specified title
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]]
Tom Wright
2016-Jul-26 19:44 UTC
[R] R3.3.1 - Windows10 OS - Overriding default Legend title with user specified title
A quick google for "ggplot2 change legend text" turns up several hits. This stackexchange question has several recipes. http://stats.stackexchange.com/questions/5007/how-can-i-change-the-title-o f-a-legend-in-ggplot2 including the correct use of the labs() function; labs(aesthetic='BrandValue in Billions') -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of udhayakanth reddy Sent: July 26, 2016 12:02 PM To: r-help at r-project.org Subject: [R] R3.3.1 - Windows10 OS - Overriding default Legend title with user specified title 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_ r+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]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.