tidyverse

geom_abline multiple slopes and intercepts

你离开我真会死。 提交于 2019-12-24 03:42:14
问题 Considering this initial data frame (yld_sum): coef pred se ci.lb ci.ub cr.lb cr.ub Yld_class b0 3164.226 114.256 2940.289 3388.164 2142.724 4185.728 1Low b1 -20.698 3.511 -27.580 -13.816 -50.520 9.124 1Low b0 3985.287 133.220 3724.180 4246.394 2954.998 5015.576 2Low b1 -14.371 4.185 -22.573 -6.168 -44.525 15.784 2Low How can I simplify my syntax to plot the two estimated regression lines with their respective CI, and obtain the following plot? This is my verbose code: library(tidyverse) yld

Plotly scaleY not working across subplot rows

心不动则不痛 提交于 2019-12-23 23:25:06
问题 Building up on another question (How to remove duplicate legend entries w/ plotly subplots()), I am facing a new problem. I want all plots in both rows to have the same Y-axis. However, If I turn "shareY = TRUE", the plots on the upper row share an axis, and the plots on the lower row do, but the axis differ from one another. The code is basically the one from the answer by @Joris Chau, but added "shareY = TRUE" on the last line. library(plotly) library(tidyverse) mpg %>% mutate_at("trans",

Using R, apply multiple chi-square contingency table tests to a grouped data frame and add a new column containing the p values of the tests

此生再无相见时 提交于 2019-12-23 18:47:46
问题 I have a data frame similar to the example below (which is a small extract of my actual data frame). frequencies <- data.frame(sex=c("female", "female", "male", "male", "female", "female", "male", "male", "female", "female", "male", "male", "female", "female", "male", "male"), ecotype=c("Crab", "Wave", "Crab", "Wave", "Crab", "Wave", "Crab", "Wave", "Crab", "Wave", "Crab", "Wave", "Crab", "Wave", "Crab", "Wave"), contig_ID=c("Contig100169_2367", "Contig100169_2367", "Contig100169_2367",

tidyr:Pivot_wider replace values with data type

冷暖自知 提交于 2019-12-23 16:36:45
问题 I have a data frame with variables in the rows and the columns that both contain variables, so I am trying to use pivot wide tidy the data. My data looks like the following: head(df) # A tibble: 6 x 4 State Year Var X <chr> <dbl> <chr> <dbl> 1 ALABAMA 2001 APPALACHIAN REGIONAL COMMISSION (ARC) 3048031 2 ALABAMA 2001 CORPORATION FOR NATIONAL AND COMMUNITY SERVICE (CNCS) 1765835 3 ALABAMA 2001 DEPARTMENT OF AGRICULTURE (USDA) 282530429 4 ALABAMA 2001 DEPARTMENT OF COMMERCE (DOC) 17838084 5

How can I use accumulate like reduce2 function in purrr?

馋奶兔 提交于 2019-12-23 15:44:50
问题 I would like to use the accumulate function with two input vectors and the reduce2 function. The documentation for accumulate implies that two input vectors can be given and that accumulate can work with reduce2 . However, I am having trouble. Here is an example, inspired by the documentation from reduce2 . This is the example from reduce2 > paste2 <- function(x, y, sep = ".") paste(x, y, sep = sep) > letters[1:4] %>% reduce2(.y=c("-", ".", "-"), paste2) [1] "a-b.c-d" Here are several

Create a unique legend based on a contingency (2x2) table in geom_map or ggplot2?

风格不统一 提交于 2019-12-23 09:57:18
问题 How can I do this based on this contingency table? I'm not entirely sure how to create a custom legend in R based on the indicator table I made (crimes). Reproducible code in R: require(maps) set.seed(123) # randomly assign 2 variables to each state mappingData <- data.frame(state = tolower(rownames(USArrests)), iceCream = (sample(c("Likes Ice Cream","Doesn't Like Ice Cream"),50, replace=T)), hotDogs = (sample(c("Likes Hot Dogs","Doesn't Like Hot Dogs"),50, replace=T))) # create a 'legend'

Simulating a timeseries in dplyr instead of using a for loop

感情迁移 提交于 2019-12-23 09:15:55
问题 So, while lag and lead in dplyr are great, I want to simulate a timeseries of something like population growth. My old school code would look something like: tdf <- data.frame(time=1:5, pop=50) for(i in 2:5){ tdf$pop[i] = 1.1*tdf$pop[i-1] } which produces time pop 1 1 50.000 2 2 55.000 3 3 60.500 4 4 66.550 5 5 73.205 I feel like there has to be a dplyr or tidyverse way to do this (as much as I love my for loop). But, something like tdf <- data.frame(time=1:5, pop=50) %>% mutate(pop = 1.1*lag

Return counts of matches and unique items for all pairwise comparisons within subsets

☆樱花仙子☆ 提交于 2019-12-23 07:13:05
问题 I have a data frame of plant plantsp and herbivore lepsp species and their interactions int1 and int2 with sampling nested in site , season and group . I wish to create a loop that makes pairwise comparisons among each level of group collected within each site and season subset. Fore each pairwise comparison I will calculate total MATCHING and UNIQUE interactions among int1 and int2 . I have devised the following steps to break down this problem: Consider the following example data frame df :

Return counts of matches and unique items for all pairwise comparisons within subsets

烈酒焚心 提交于 2019-12-23 07:11:06
问题 I have a data frame of plant plantsp and herbivore lepsp species and their interactions int1 and int2 with sampling nested in site , season and group . I wish to create a loop that makes pairwise comparisons among each level of group collected within each site and season subset. Fore each pairwise comparison I will calculate total MATCHING and UNIQUE interactions among int1 and int2 . I have devised the following steps to break down this problem: Consider the following example data frame df :

how to create new variables from one variable using two rules

只谈情不闲聊 提交于 2019-12-23 05:59:57
问题 I would appreciate any help to create new variables from one variable. Specifically, I need help to simultaneously create one row per each ID and various columns of E , where each of the new columns of E , (that is, E1 , E2 , E3 ) contains the values of E for each row of ID . I tried doing this which melt followed by spread but I am getting the error: Error: Duplicate identifiers for rows (4, 7, 9), (1, 3, 6), (2, 5, 8) Additionally, I tried the solutions discussed here and here but these did