1

I have a dataset with records that have two variables: "time" which are id's of decades, and "latitude" which are geographic latitudes. I have 7 time periods (numbered from 26 to 32).

I want to visualize a potential shift in latitude through time. So what I need ggplot2 to do, is to plot a graph with latitude on the x-axis and the count of records at a certain latitude on the y-axis. I need it do this for the seperate time periods and plot everything in 1 graph.

I understood that I need the function freqpoly from ggplot2, and I got this so far:

qplot(latitude, data = lat_data, geom = "freqpoly", binwidth = 0.25)

This gives me the correct graph of the data, ignoring the time. But how can I implement the time? I tried subsetting the data, but I can't really figure out if this is the best way..

So basically I'm trying to get a graph with 7 lines showing the frequency distribution in each decade in order to look for a latitude shift.

Thanks!!

1 Answer 1

1

Without sample data it is hard to answer but try to add color=factor(time) (where time is name of your column with time periods). This will draw lines for each time period in different color.

qplot(latitude, data = lat_data, geom = "freqpoly", binwidth = 0.25,
                  color=factor(time))
Sign up to request clarification or add additional context in comments.

1 Comment

You need to add factor() if your time variable is numeric

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.