readersm / Master-s-Program

This is a place to house and modify my program of study and keep track of any program-related information
0 stars 0 forks source link

Weather data - 2 Y-axis issue #9

Closed readersm closed 4 years ago

readersm commented 4 years ago

I'm trying to map the temp and precip together for each season, but I keep getting the error Error in UseMethod("rescale") : no applicable method for 'rescale' applied to an object of class "character" but they are all numbers. The only character is Day, and when I reassign it as a number, it gives me this error "Error: Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?" weather summer 2020

geom_bar(mapping = aes(x = data_for_graph$Day, y = data_for_graph$rain), stat = "identity", fill = "grey")+ geom_line(mapping = aes(x = data_for_graph$Day, y= data_for_graph$temp), color ="red")+ scale_x_discrete(name = "Day", labels = NULL)+ scale_y_continuous("Precipitation (mm)", sec.axis = sec_axis(~ ./2), name="Temperature (C)") + ggtitle("Temperature and rainfall for Summer 2020 growing cycle")

brymz commented 4 years ago

Big picture: I don't think it's very important for you to report these weather data in this much detail. Perhaps, a table of avg/min/max rain and temp for each of the crop cycles would be sufficient values.

Troubleshooting: What is class(data_for_graphs$Day)? I have not seen different y-axis plotted together in R. The best practice would be to have separate plots for rain and temp. Remember the steps for troubleshooting that strip as much complexity from the code in a manner that allows you to investigate the functionality of each of the individual pieces. It also looks to me like scale_x_discrete() is a bit misused here. ggplot2 docs suggest labs() for what you're asking. Also, notice that the name for the y-axis is not "Temperature (C)" and their is no title, another indication of the location where there is something not properly functioning.