in Education by
I'm trying to plot a geom_rect(). Why do I receive an Error in FUN(X[[i]], ...) : object 'Month' not found? If I run df$Month in my console the object is there: df$Month #> [1] 2019-01 2019-02 2019-03 #> Levels: 2019-01 2019-02 2019-03 Here's my code block: library(tidyverse) df <- tibble(Month = factor(c("2019-01", "2019-02", "2019-03")), Value = c(4, 9, 7)) ggplot(df, aes(Month, Value, group = 1)) + geom_line() + theme_minimal() + geom_rect(data = data.frame(xmin = min(as.integer(df$Month)) - 0.5, xmax = max(as.integer(df$Month)) + 0.5, ymin = min(df$Value), ymax = max(df$Value)), aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax), alpha = 0.2, fill = "green") #> Error in FUN(X[[i]], ...) : object 'Month' not found JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You just have an extra step of setting up a dataframe in geom_rect which coincide with data in ggplot. Simply provide your max and min values to geom_rect and it works: ggplot(df, aes(Month, Value, group = 1)) + geom_line() + theme_minimal() + geom_rect(aes(xmin = min(as.integer(Month)) - 0.5, xmax = max(as.integer(Month)) + 0.5, ymin = min(Value), ymax = max(Value)), alpha = 0.2/nrow(df), fill = "green")

Related questions

0 votes
    ________ modify a ggplot or theme object by adding on new components. (a) +.gg (b) -.gg (c) /.gg ... Data Analysis of R Programming Select the correct answer from above options...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    I am running the code and it works ggplot(data_df, aes(x= RR, y= PPW, col = year)) + ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I have a list of ggplots of simple ggplot line graphs based on a location. I created a list of ggplot ... (rnaturalearthdata) library(dplyr) library(ggthemes) #create line plot x...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Which of the following creates a new ggplot plot from a data frame? (a) qplot_ggplot (b) ggplot.data. ... Analysis of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    __________ create a complete ggplot appropriate to a particular data type. (a) autoplot (b) is.ggplot (c) ... of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I write this code in R to produce a csv file from my diff function, but I'm getting that error. for(girdi1 in 1:304) { print(girdi1) meslek1...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    ________ function is usually used inside another function and throws a warning whenever a particular package is not ... R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    In practice, Line of best fit or regression line is found when _____________ (a) Sum of residuals (∑(Y ... Regression of R Programming Select the correct answer from above options...
asked Feb 9, 2022 in Education by JackTerrance
0 votes
    I am new to spring-maven-hibernate and i cannot solve this following error here is my console output. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
0 votes
    When I try to open the Plesk Login Page via :8443 I get the Error: ERROR: Uncaught Error: Class ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    I am getting an error after I put my application in an AdMob. The app was working until today. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I'm trying to install some machine learning libraries on a new Windows laptop (I usually have Mac laptops ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I'm trying to install some machine learning libraries on a new Windows laptop (I usually have Mac laptops ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I'm trying to install some machine learning libraries on a new Windows laptop (I usually have Mac laptops ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    axios.js throws CONNRESET error (certificate not found in request) but request package works for same p12 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
...