0

I want a line between all my detections points, how can I get this?

Geomline

When I run:

AT.data_posisjon %>%
  filter(ID %in% Tag_84) %>%
  ggplot(aes(x=DateTime,y=Array,color=Section))+
  geom_point()+
  geom_line() 

I got only line between points in the same section, but I want a line between different sections too.

benson23
  • 16,369
  • 9
  • 19
  • 38

1 Answers1

0

Your geom_point and geom_line inherits its aesthetics from the "global" one provided in the ggplot-call. In other words, the rows in the data frame gets divided into groups, based on your Section, for both geom_point and geom_line.

One solution is to move the color-specification to to geom_point, ie.

ggplot(aes(x=DateTime, y=Array)) +
  geom_point(aes(color=Section)) +
  geom_line()

This the color of the line connecting all the dots is black -- the same color for all rows.

If you want the line connecting the dots to have the same color as the dots, you have to ask yourself: A line that connects two dots of different color, what color should the line have?

If you can "nøjes" with "intersection"-lines being black, we can draw colored lines on top of the black ones:

ggplot(aes(x=DateTime, y=Array)) +
  geom_point(aes(color=Section)) +
  geom_line() +  # black line between all dots
  geom_line(aes(color=Section)) # a *new* set of lines, which are drawn *on top*, but only "within" each section.
MrGumble
  • 5,631
  • 1
  • 18
  • 33