0

I have the below table on data "data_temp" and I'm trying to plot a trend line using "geom_line", but line does not appear.

> head(data_temp,15)

             Mês    n
    1    Janeiro 7432
    2  Fevereiro 7077
    3      Março 7494
    4      Abril 7760
    5       Maio 7755
    6      Junho 7516
    7      Julho 7320
    8     Agosto 7084
    9   Setembro 7134
    10   Outubro 7390
    11  Novembro 6973
    12  Dezembro 8622

This is the code I used:

ggplot(data = data_temp, aes(x=Mês, y=n))+
  geom_line() +
  geom_point()

You can see below that the points work, but the line does not appear.

Tren chart with no line

I tried so many codes in a different way, but I haven't suceed so far. I hope anyone can help me.

  • The x = "Mês", means "Month", but is in portuguese.

Many thanks,

Wil

Martin Gal
  • 16,640
  • 5
  • 21
  • 39
Wil
  • 47
  • 4

1 Answers1

0

Try

library(ggplot2)
ggplot(data = data_temp, aes(x=Mês, y=n, group=1))+
  geom_line() +
  geom_point()

to get

enter image description here

The geom_line-functions needs a group to "know" which dot's should be connected. Since you don't have a grouping variable in your data, you simply add group = 1 to group all dots into the same group.

Martin Gal
  • 16,640
  • 5
  • 21
  • 39
  • Marvelous! Thank you @Martin Gal . It worked. Many thanks for sharing your knowledge! – Wil Jul 11 '21 at 23:16