0

I created a dataframe datos_f.csv with 5 columns (date, months, pp, tmax and tmin) from meteorological .csv data.

I've been trying to plot a time series using one of these variables and the dates, but ggplot2 doesn't plot. It only shows the axis.

I'm novice in R, but I'm trying different methods and nothing is working.

Thanks so much for reading!

My dataframe (with 16071 rows) is:

> head(datos_f)
       fecha   mes  pp tmax tmin
1  1970-01-01 Enero 0.0 29.9 18.2
2  1970-01-02 Enero 0.0 30.3 18.4
3  1970-01-03 Enero 0.0 31.0 18.0
4  1970-01-04 Enero 0.0 29.9 16.8
5  1970-01-05 Enero 0.0 30.2 19.4
6  1970-01-06 Enero 0.0 31.6 18.7
7  1970-01-07 Enero 0.0 32.2 17.8
8  1970-01-08 Enero 0.0 32.0 19.2
9  1970-01-09 Enero 0.0 34.2 18.8
10 1970-01-10 Enero 0.0 33.0 17.4
11 1970-01-11 Enero 0.0 32.8 17.2
12 1970-01-12 Enero 0.0 30.6 18.3
13 1970-01-13 Enero 0.0 33.2 19.4
14 1970-01-14 Enero 0.0 29.4 19.8
15 1970-01-15 Enero 3.9 29.8 20.0

I used this simple order:

ggplot(data=datos_f,aes(x=fecha,y=tmax),geom_point(size=2))

but this shows me an empty image with only the axis:

enter image description here

Any ideas?

3
  • 3
    You need ggplot(data=datos_f,aes(x=fecha,y=tmax)) + geom_point(size=2) Layers are added with a +. You might want to go through a ggplot2 tutorial to get start with the syntax; some are listed here: ggplot2.tidyverse.org Commented Jul 5, 2019 at 8:55
  • thanks so much!! Now it works!, that was so obvious t-t i dind´t notice. Sorry Commented Jul 5, 2019 at 9:02
  • If you do this often, you may want to know that there's actually a neat plot.xts-method implemented into xts package which I assume you're using. Commented Jul 5, 2019 at 9:07

1 Answer 1

2

ggplot2 syntax is a little bit different from normal R syntaxes. It uses + operator.

ggplot(data=datos_f,aes(x=fecha,y=tmax)) + geom_point(size=2)

Here + operator overloads the function geom_point on the ggplot object

Sign up to request clarification or add additional context in comments.

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.