1

I am using the following code to plot in R:

q <- qplot(var1, var2, data=data_1)
q + theme(axis.text.x = element_text(angle = 90, hjust = 1))

which gives me this plot:

enter image description here

How can I get a line which connects the dots of the various points?

Here are the datasets:

> cat(sprintf("\"%s\" \"%f\"\n", data_1$var1, data_1$var2))
"2012Q1" "NA"
 "2012Q2" "NA"
 "2012Q3" "NA"
 "2012Q4" "NA"
 "2013Q1" "81890.091966"
 "2013Q2" "80068.697510"
 "2013Q3" "304742.176778"
 "2013Q4" "223182.661337"
 "2014Q1" "275189.419519"
 "2014Q2" "297179.617112"
 "2014Q3" "284532.546842"
 "2014Q4" "416008.842763"
 "2015Q1" "381822.813657"
 "2015Q2" "410020.242215"
 "2015Q3" "384865.684379"
 "2015Q4" "425738.393387"
 "2016Q1" "382404.239015"
 "2016Q2" "378516.717327"
 "2016Q3" "338451.013178"
 "2016Q4" "351486.235708"
 "2017Q1" "366015.605164"
 "2017Q2" "358818.529895"
 "2017Q3" "325981.821170"
 "2017Q4" "371457.620454"
 "2018Q1" "410345.839819"
 "2018Q2" "398976.425498"
 "2018Q3" "362460.336773"
 "2018Q4" "375626.057926"
 "2019Q1" "361636.409126"
 "2019Q2" "378178.181764"

2 Answers 2

1

You can just add geom_line(), like:

q <- qplot(var1, var2, data=data_1)
q <- q + geom_line(aes(group = 1))
q + theme(axis.text.x = element_text(angle = 90, hjust = 1))
Sign up to request clarification or add additional context in comments.

Comments

0

try using + geom_line() check this very similar question

https://stackoverflow.com/questions/8592585/combine-points-with-lines-with-ggplot2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.