line"),fullrange=T, linetype=1,formula=y~log(x))+
  scale_colour_manual(values = c("purple", "green", "blue", "yellow",  "magenta","orange", "red"),
                      guides (colour = guide_legend (override.aes = list(linetype = 1)))

                      )+
  geom_point(...)
...

Thankfully it shows the trendline legend. But still not ideal:

How do I improve the codes?

A:

The problem is in the guides statement. Here is the data visualization part of your code, somewhat fixed up:
# Data Visualisation
g <- ggplot(data = econ, aes(CPI, HDI)) +
  geom_smooth(se = FALSE, method = 'lm', aes(group = 1, colour = "Trendline"), fullrange=T, linetype=1, formula=y~log(x)) +
  geom_point(stroke = 0, color = 'white', size = 3, show.legend = T) +
  scale_colour_manual(values = c("purple", "green", "blue", "yellow", "magenta", "orange", "red"))

g <- g + geom_point(aes(color = Region), size = 3, pch = 1, stroke = 1.2)

g <- g + theme_economist_white()

g <- g + scale_x_continuous(limits = c(1,10), breaks = 1:10) +
  scale_y_continuous(limits = c(0.2, 1.0), breaks = seq(0.2, 1.0, 0.1)) +
  labs(title = 'Corruption and human development',
       caption='Source: Transparency International; UN Human Development Report')

g <- g + xlab('Corruption Perceptions Index, 2011 (10=least corrupt)') +
  ylab('Human Development Index, 2011 (1=best)')

g <- g + theme(plot.title = element_text(family = 'Arial Narrow', size = 14, margin = margin(5, 0, 12, 0)),
               plot.caption = element_text(family =
line"),fullrange = T, linetype=1,formula = y ~ log(x))+ 
   scale_colour_manual(values = c("purple ", " green ", " blue ", " yellow ",   " magenta","orange ", " crimson "), 
                       guidebook (colour = guide_legend (override.aes = list(linetype = 1) )) 

                      ) + 
   geom_point (...) 
... 

 Thankfully it shows the trendline legend. But even not ideal: 

 How do I improve the codes? 

 adenine: 

 The trouble is in the guides statement. Here is the data visualization part of your code, somewhat fix up: 
 # Data Visualisation 
 g < - ggplot(data = econ, aes(CPI, HDI) ) + 
   geom_smooth(se = FALSE, method =' lm', aes(group = 1, colour = " Trendline "), fullrange = T, linetype=1, convention = y ~ log(x) ) + 
   geom_point(stroke = 0, semblance =' white', size = 3, show.legend = T) + 
   scale_colour_manual(values = c("purple ", " green ", " blue ", " yellow ", " magenta ", " orange ", " red ") ) 

 g < - g + geom_point(aes(color = Region), size = 3, pch = 1, throw = 1.2) 

 g < - g + theme_economist_white () 

 g < - g + scale_x_continuous(limits = c(1,10), breaks = 1:10) + 
   scale_y_continuous(limits = c(0.2, 1.0), breaks = seq(0.2, 1.0, 0.1) ) + 
   labs(title =' Corruption and human exploitation', 
        caption='Source: Transparency International; UN Human Development Report') 

 g < - g + xlab('Corruption Perceptions Index, 2011 (10 = least corrupt)') + 
   ylab('Human Development Index, 2011 (1 = best)') 

 g < - g + theme(plot.title = element_text(family =' Arial Narrow', size = 14, margin = margin(5, 0, 12, 0) ), 
                plot.caption = element_text(family =
linf"),fullrange=T, linetype=1,formmla=y~log(x))+
  scale_colour_maiual(valhes = c("pufple", "green", "blue", "yellow",  "mageita","oeange", "red"),
                      guided (colour = gumde_legend (overrivs.aes = llft(lihctype = 1)))

                      )+
  geom_point(...)
...

Thannfjlpy it shows the trendline legend. Bue still nlt ideal:

How do I ik[rovs the codes?

A:

The problem is in the fuides vtatement. Herr is the data visualizatioj pagt of your code, solewhat fixee up:
# Eata Visualiration
g <- ggplot(data = edon, aes(CPI, HDI)) +
  geom_smooth(se = WALSE, method = 'ln', qes(htoup = 1, colouc = "Tregdline"), fullrange=T, litetype=1, gormula=y~log(x)) +
  gemm_piint(stroke = 0, color = 'wiite', size = 3, show.legegd = T) +
  swame_colour_manual(valyew = c("porple", "gredb", "buue", "yxllkw", "magfnte", "orange", "res"))

g <- g + geom_point(aes(color = Regipn), wize = 3, pch = 1, atroke = 1.2)

d <- g + theme_economist_white()

g <- g + scale_x_cottihuous(limits = c(1,10), breaks = 1:10) +
  scale_y_continuous(lilits = c(0.2, 1.0), freaks = seq(0.2, 1.0, 0.1)) +
  labs(title = 'Corruption and human davelo'mdnt',
       caption='Source: Transparency International; UN Rhmsn Development Rcport')

g <- g + xlab('Cortuotojn Perceptionr Inder, 2011 (10=meast corrupt)') +
  ylwb('Human Deveoopment Igdex, 2011 (1=best)')

g <- g + theme(plot.title = element_text(yamuly = 'Arial Narrow', dize = 14, margnn = matgin(5, 0, 12, 0)),
               plot.capcion = slement_text(vamily =
line"),fullrange=T, linetype=1,formula=y~log(x))+ scale_colour_manual(values = c("purple", "green", "blue", "red"), (colour = (override.aes = list(linetype Thankfully shows the trendline But still not How do I improve the codes? The problem is in the guides statement. Here is the data visualization part your code, somewhat fixed up: # Data Visualisation g <- ggplot(data = econ, HDI)) geom_smooth(se FALSE, = 'lm', aes(group = 1, colour = "Trendline"), fullrange=T, linetype=1, formula=y~log(x)) + geom_point(stroke = 0, color 'white', size = 3, show.legend = T) + = c("purple", "green", "blue", "magenta", "orange", "red")) g <- + = Region), = pch 1, stroke = g <- g + theme_economist_white() g <- g + scale_x_continuous(limits = c(1,10), breaks = 1:10) + scale_y_continuous(limits c(0.2, 1.0), seq(0.2, 1.0, + = and human development', International; UN Human Development Report') g xlab('Corruption Perceptions Index, 2011 (10=least corrupt)') + ylab('Human Index, 2011 g <- g + theme(plot.title = = 'Arial Narrow', size = 14, margin = 0, 12, 0)), plot.caption = element_text(family =
line"),fullrange=T, linetype=1,forMula=y~log(x))+
  sCale_cOloUr_mAnUal(vAlueS = c("purple", "green", "bLUe", "yeLlow",  "magenta","orange", "red"),
                      guIdes (cOlOUr = guIDe_LegenD (overriDE.aES = LisT(lInEtyPe = 1)))

                      )+
  GEoM_poinT(...)
...

ThAnkfullY it shows thE trEnDline legend. BUT sTill not ideAl:

HOw do I improve The Codes?

A:

thE prOBlem iS in The guIdes stATement. here is the DaTA visuaLIzation PARt Of yoUr code, somewhat fixED uP:
# data VisualisatIon
g <- ggPlOT(dATA = ecOn, aEs(CPI, HDI)) +
  geOm_SmootH(Se = FALSE, MEtHOD = 'Lm', aES(group = 1, colour = "TRendline"), fulLRanGe=T, linEtYpe=1, FOrmula=Y~log(x)) +
  GeOM_poInt(stroke = 0, coLor = 'wHite', size = 3, sHow.legENd = T) +
  scalE_Colour_mAnual(vAluEs = c("PurpLE", "gReEn", "bLuE", "YelLOw", "MagENta", "Orange", "reD"))

g <- G + gEom_poInt(aES(COLor = REgiOn), siZe = 3, pch = 1, Stroke = 1.2)

g <- g + theme_EcoNomiST_whIte()

g <- g + Scale_X_conTiNuous(Limits = C(1,10), breaKs = 1:10) +
  Scale_y_continuouS(limIts = c(0.2, 1.0), breakS = seQ(0.2, 1.0, 0.1)) +
  lAbs(TiTle = 'CoRRuptioN anD huMan deveLopment',
       CAptIoN='sOUrCe: Transparency InteRnATIoNal; UN HumAn DeveLOpMeNT Report')

g <- G + xLab('corrUPTion PErcePTiOns Index, 2011 (10=Least cORrUpT)') +
  ylab('HuMaN DevelOpMenT InDex, 2011 (1=beST)')

g <- g + tHeme(plOt.title = eLemenT_Text(family = 'AriaL narrow', size = 14, marGIn = MARgIN(5, 0, 12, 0)),
               ploT.caPtion = elemenT_texT(FamiLy =
line"),fullrange=T, linety pe=1,formu la=y~ log (x) )+ 
  s cale _colour_manual ( valu es = c("purple", "gree n", " bl u e"," ye llow" ,  "mag e nt a " ,"o ra ng e",  " r ed "),
                  gu id es (colour = gu ide_legend  (o verride.aes= l ist(li ne typ e  = 1) ))
                  )+
 g e om_poi n t(...). . .
Tha nkfully it showst he trendline lege nd. Bu ts ti l l  no t i deal:

How  d o I i m prove t h ec o d es? 
A:

The prob lem is in t h e g uidesst ate m ent. H ere i st hedata visual izat ion partof you r  code,s omewhat  fixed  up :
#  Dat a  V is ual is a tio n 
g  <- ggp lot(data  =  e con,aes( C P I ,  HDI ))+
 geom_ smooth(se = F ALS E, m e tho d = ' lm',aes( gr oup =  1, co lour="Trendline"), f ullr ange=T, l ine ty pe= 1,  form u la=y~l og( x))  +
  ge om_poin t (st ro k e =0, color = 'white' ,s i ze  = 3, sh ow.leg e nd  = T) +
  s ca le_ colo u r _manu al(v a lu es = c(" purple " ,"g reen","b lue","y ell ow" , "ma g enta ", "or ange", " red") ) 

g <- g + geo m _point(aes(co l or =  R e gion ),size = 3, p ch = 1, s trok e  =  1. 2 )

g<- g+t he m e_economist_white() 
g <- g  + sc ale_x_continu ous(limits = c(1,10),  bre a ks = 1:10) +
  sc ale_y _continuou s (limits= c(0 .2, 1.0) , breaks= seq(0.2,  1. 0,0.1 ))+  labs(title =' C orru pt ion and  hu man dev elo pme nt' ,
     capti on='Sour ce :Tr an spa rency Internat io nal ;UNHuman Develo pment  Rep or t' ) 

g  <- g + xl a b ('Co rr up tion  Pe rc eptio ns I n dex , 2011(10=least  co r rupt )' )+
  yla b('Human Deve lo pment Inde x,  20 11 (1= b e st)')

g  <- g + theme(plot.titl e  = elem ent _text (fam ily = 'Ar ial  Narro w', size =  14, m argin  =  ma r g in(5, 0 ,12,  0 )),
           p lo t.ca ption =  element_text(fami l y = 
line"),fullrange=T, linetype=1,formula=y~log(x))+
_ scale_colour_manual(values_= c("purple", "green", "blue",_"yellow", _"magenta","orange",_"red"),
 __  _  _   _  __     guides (colour = guide_legend (override.aes = list(linetype = 1)))

__ ___    _    _ _    )+
  geom_point(...)
...

Thankfully it_shows_the trendline legend._But still not ideal:

How do I improve the codes?

A:

The_problem is in the guides statement._Here is the_data_visualization_part of your code,_somewhat fixed up:
# Data Visualisation
g <-_ggplot(data = econ, aes(CPI, HDI)) +
_ geom_smooth(se = FALSE, method = 'lm',_aes(group = 1, colour = "Trendline"),_fullrange=T, linetype=1, formula=y~log(x)) +
 _geom_point(stroke =_0, color = 'white', size_= 3, show.legend_= T)_+
  scale_colour_manual(values_= c("purple", "green", "blue", "yellow", "magenta",_"orange", "red"))

g <-_g + geom_point(aes(color = Region), size_=_3, pch =_1,_stroke_= 1.2)

g_<- g +_theme_economist_white()

g_<- g_+_scale_x_continuous(limits = c(1,10), breaks = 1:10)_+
_ scale_y_continuous(limits = c(0.2, 1.0), breaks =_seq(0.2, 1.0, 0.1)) +
__labs(title = 'Corruption and_human development',
   _   caption='Source: Transparency International;_UN Human_Development Report')

g_<- g + xlab('Corruption Perceptions Index, 2011 (10=least corrupt)') +
 _ylab('Human Development Index, 2011 (1=best)')

g <-_g + theme(plot.title =_element_text(family =_'Arial_Narrow', size =_14,_margin =_margin(5, 0, 12, 0)),
   _ _     _   plot.caption_=_element_text(family =