Beginner Looking for Help Converting Data into Graphs

I am a student at NDSU working on a project related to colony collapse disorder in the United States. I am trying to make a basic scatterplot of my dataset and am struggling to do so. Attached is a screenshot showing my problem. I am very new to all of this and very confused, but determined to figure out how to graph my data. Please help!!

Hi @SamGoody21,

A few points to note:

  • R is case-sensitive, so you need to be careful with spelling errors. Notice that your variable is spelt Year rather than year as you have typed in your ggplot() code. This is why R could not find year.
  • You are missing some closed parentheses which is why R is waiting to see the closed parenthesis, which is shown by the + symbol in the console. Make sure all open parentheses get closed.
  • The function ggplot() won't produce a graph by itself, it only collects the information needed to make a graph. You still need to add geometries to the graph.

Try out this code using your data:

ggplot(Bee_Colony_Loss, aes(x = State, y = Beekeepers)) +
  geom_point()

You specify the data you are going to plot in the ggplot() function, and then tell ggplot() which type of plot by specifying the geometry (geom_point()), which will plot the data as points (i.e. a scatterplot).

3 Likes

Hi Matt,
Thanks for responding. I see some of the points you are making, but still am struggling to form a graph. Heres another screenshot

Hi @SamGoody21,

In general, screenshots aren't usually too helpful for debugging code. It is easier for me (or others) to help if you create a reproducible example. This means providing the code (as text, not an image) that we can copy-and-paste to our own sessions to try and reproduce the same error.

However, the code isn't enough, we would also need the data you are running the code on. If you are not able to share the data, then you should try to reproduce the error with some "fake" data.

Try running this code to make sure everything is working fine:

ggplot(iris, aes(Sepal.Length)) + 
  geom_histogram()
1 Like

Okay, thanks for the heads up! I will try that code and get back to you immediately. Thanks again Matt!

The code you told me to do works.

Okay, and when you try this code it doesn't work?

ggplot(Bee_Colony_Loss, aes(x = State, y = Beekeepers)) +
  geom_point()

Correct. It says "Object 'State' not found." I can email you the dataset if you'd like to fiddle around with it.

Is your data set loaded into memory? The above code I shared will only work if you have the data set Bee_Colony_Loss loaded into memory in R, and it must contain the variables State and Beekeepers.

Well I just converted the data to .csv (comma separated values). How to I load it into memory?


Sorry to send another screenshot, but this could be part of the problem.

Use encoding = "latin1" in locale.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.