Adding a unique trend line to a barplot in GGPLOT2

This is partly due to my question yesterday.

So, here is the data and graph created in ggplot2.

df = data.frame(date=c(rep(2008:2013, by=1)),
                value=c(303,407,538,696,881,1094))


ggplot(df, aes(date, value, width=0.64)) + 
        geom_bar(stat = "identity", fill="#336699", colour="black") +
        ylim(c(0,1400)) + opts(title="U.S. Smartphone Users") +
        opts(axis.text.y=theme_text(family="sans", face="bold")) +
        opts(axis.text.x=theme_text(family="sans", face="bold")) +
        opts(plot.title = theme_text(size=14, face="bold")) +
        xlab("Year") + ylab("Users (in millions)") +        
        opts(axis.title.x=theme_text(family="sans")) +
        opts(axis.title.y=theme_text(family="sans", angle=90)) +
        geom_segment(aes(x=2007.6, xend=2013, y=550, yend=1350), arrow=arrow(length=unit(0.4,"cm")))

Is it possible to create a short trend line in the following chart with ggplot2

I created a plot in R and then made it ready in Adobe Photoshop, and I wonder if it can create this straight trend line right in R.

If this cannot be done in ggplot2, are there any specific R packages that will succumb to this task?

I do not ask about the reproduction of the schedule. It's not a problem. Just creating a trend line seems like a problem.

enter image description here

+5
source share
2 answers

: , . ( , , .) " ".

, , , , .

, , geom_line. , , . , p

p + geom_line(
  aes(date, value), 
  data = data.frame(
    date = seq(2008, 2013, length.out = n),
    value = seq(600, 1300, length.out = n) + 100 * sin(seq(0, 4 * pi, length.out = n))  
  ), 
  arrow = arrow(length = unit(0.4, "cm"))
)

.

p + geom_smooth(method = "loess", se = FALSE)  #maybe also span = 0.5, for extra wigglyness.
+8

: R. R . , , - . Illustrator, Inkscape () , . , R .

, . , " --". . , , , . , , . - R, .

+3

All Articles