ggplot - each axis different column of df

I want to create ggplot where X axis will include data from one column of the data frame and Y axis will include data from other column of the data frame.

This is the command:
geom_point(diseases_california,mapping = aes(x=diseases_california[,6], y=diseases_california[,7]))

This is the output:

The typical way to refer to data frame columns in ggplot is by name. Let's say column 6 is named Year and column 7 is named Cases.

geom_point(data = diseases_california,mapping = aes(x = Year, y = Cases))

If something like that does not work, please post a reproducible example.

FJCC is right, but even with your syntax you should be getting a result, so it is very likely that there is a problem with the structure of your data set. In order to help you with that please provide a minimal REPRoducible EXample (reprex) of your issue.

For example this is a reprex with some built-in data, you could do the same but with a subset of your own data.


diseases_california <- iris # Madeup data

ggplot() +
    geom_point(diseases_california, mapping = aes(x = diseases_california[,1],
                                                  y = diseases_california[,2]))

Created on 2019-06-02 by the reprex package (v0.3.0)

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