Error in geompoint(data = lemursdf, mapping = aes(x = ageatdeath_y), : ℹ Error occurred…
- User
Error in geom_point(data = lemurs_df, mapping = aes(x = age_at_death_y), : ℹ Error occurred in the 1st layer. Caused by error in
desc(): !xmust be a vector, not a function. - Assistant
This error message suggests that there is an issue with the
geom_point()function in the ggplot2 package. Specifically, it seems that the error is occurring in the mapping of the x-axis variable using theaes()function.The error message mentions that the problem is caused by the
desc()function, which is likely being applied to thexvariable. Thedesc()function is used to reverse the order of a variable in a plot.To fix this error, check the variable
age_at_death_yto ensure that it is a vector and not a function. You can do this by checking the structure of the variable using thestr()function. Make sure it is a numerical or categorical variable, and not a function that returns a vector. Fixing any issues with the variable should resolve the error. - User
lm_data <- lemurs_df1 %>% nest(data = -c(dlc_id, age_at_death_y)) %>% mutate( fit = map(data, ~lm(age_at_death_y ~ log(common_name), data = .x)), tidy_out = map(fit, tidy) ) %>% unnest(cols = tidy_out) %>% select(-fit, -data) %>% filter(term != "(Intercept)", continent != "Oceania")
- Assistant
The code snippet provided performs the following steps:
- It nests the data frame
lemurs_df1based on the variablesdlc_idandage_at_death_y, while creating a new column calleddatato store the nested data. - It uses the
mutate()function to create two new columns:fitandtidy_out. Thefitcolumn applies thelm()function to each nested data frame, fitting a linear regression model withage_at_death_yas the dependent variable and the natural logarithm ofcommon_nameas the independent variable. Thetidy_outcolumn then applies thetidy()function to each fitted model, extracting the model coefficients and related information. - It uses the
unnest()function to unnest thetidy_outcolumn, expanding the nested data frame into individual rows. - It uses the
select()function to remove thefitanddatacolumns from the data frame.
- It nests the data frame