I am trying to add a label for a hline that I show on my plot. I can display the hline on the graph but I can not alter the title and it shows as a blank space. This is the data:
library (ggplot2)
library(ggthemes)
library(scales)
library(grid)
toy<-data.frame(naics_3=c('sector 35','sector 34','sector 33',
'sector 32','sector 31','sector 30'),
contrb_08_14=c(24.91,29.91,13.54,4.4,14.03,-0.37),
real_exports14=c(6787,4399,3351,2690,1956,1407))
And this is the code:
p<-ggplot(toy, aes(x = naics_3, y =contrb_08_14)) +
geom_point(data=toy, aes(size =(real_exports14)),
colour="#1947A3",
alpha=0.9)+
scale_size(breaks = c(50,200,800,3200,6000),
range = c(5,30),
labels = c('50 million',
'100 million',
'800 million',
'3 billion',
'6 billion'))+
geom_hline(aes(yintercept = mean(contrb_08_14),
fill='average',
linetype='dashed'),
color = "#00004C",
linetype='dashed',
data=bubble,
#show_guide = T,
alpha=0.4)+
scale_linetype(name = "Ave")+
guides(linetype = guide_legend(override.aes = list(colour = "red",
fill='purple')))+
guides(size=guide_legend(override.aes = list(size = c(4,
8,
15,
18,
24)),
title = "Exports 2014",
title.hjust = 0.5,
keywidth=0.3))+
coord_flip()+
theme(plot.margin=unit(c(0.0,0.0,0.0,0.0),"mm"))+
theme_classic()+
scale_y_continuous(limits=c(-0.05, 0.35),
breaks=c(-0.05, 0, 0.05, 0.1, 0.15,
0.2, 0.25, 0.3, 0.35),
labels = percent)+
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
#plot.background = element_rect(fill = '#F2F2F2'),
#legend.background = element_rect(fill="#F2F2F2"),
panel.background = element_blank(),
panel.border = element_blank(),
axis.line = element_line(color = 'black'))+
theme(axis.text.x=element_text(size = 9),
axis.text.y=element_text(size = 7))+
theme(legend.key = element_rect(colour = "white",
fill = "white",
size=0.5),
legend.key.size= unit(0.1,"cm"),
legend.text= element_text(size = 8),
legend.title= element_text(size = 8.5))+
theme(axis.title.x=element_blank(),
axis.title.y=element_blank())
print(p)
This is the plot produced (with entire dataset), it only displays the title 'average' which I can not modify. I would like to show the title (with a different name) and show the same dashed line it is displayed on the plot in the legend key
Thanks.