0

please help me fix this error. Not sure why R can't read my column names, take the columns and plot the scatter plot

library(ggplot2) y1 <- data2[,"Average Weekly Workplace Earnings 2016 (£)"] chart <- ggplot(data = data2, aes(x = data2[,"CO2 Emissions per Capita 2016 (tons)"], y = data2[,"Average Weekly Workplace Earnings 2016 (£)"])) chart + geom_point()` 

This is the error message `> chart <- ggplot(data = data2, aes(x = data2[,"CO2 Emissions per Capita 2016 (tons)"], y = data2[,"Average Weekly Workplace Earnings 2016 (£)"]))

chart + geom_point() Don't know how to automatically pick scale for object of type spec_tbl_df/tbl_df/tbl/data.frame. Defaulting to continuous. Don't know how to automatically pick scale for object of type spec_tbl_df/tbl_df/tbl/data.frame. Defaulting to continuous. Error in is.finite(x) : default method not implemented for type 'list' `

1 Answer 1

1

the aes function is working in the way that you only have to pass the names of the columns not the complete columns themself so instead of:

chart <- ggplot(data = data2, aes(x = data2[,"CO2 Emissions per Capita 2016 (tons)"], y = data2[,"Average Weekly Workplace Earnings 2016 (£)"])) 

try:

chart <- ggplot(data = data2, aes(x = `CO2 Emissions per Capita 2016 (tons)`, y = `Average Weekly Workplace Earnings 2016 (£)`)) 

please not that I switched the quotation from normal " to ` this makes it an object instead of a string

Hope this helps!!

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! Thank you!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.