dplyr

ggplot not properly displaying

て烟熏妆下的殇ゞ 提交于 2021-02-11 15:02:33
问题 I currently am trying to graph 2 columns in a data frame I created using ggplot I am graphing date vs. numeric value. I used dplyr library to create the dataframe: is_china <- confirmed_cases_worldwide %>% filter(country == "China", type=='confirmed') %>% mutate(cumu_cases = cumsum(cases)) I believe the reason is due to the y value being a result column of cumsum function, but am unsure The table looks something like this, the last column being the targeted y value: 2020-01-22 NA China 31

Suffixes when merging more than two data frames with full_join

人盡茶涼 提交于 2021-02-11 14:51:12
问题 I would like to used nested full_join to merge several data frames together. In addition, I am hoping to be able to add suffixes to all of the columns so that when the data frames are merged each column name indicates which data frame it came from (e.g., a unique time identifier like T1, T2, ...). x <- data.frame(i = c("a","b","c"), j = 1:3, h = 1:3, stringsAsFactors=FALSE) y <- data.frame(i = c("b","c","d"), k = 4:6, h = 1:3, stringsAsFactors=FALSE) z <- data.frame(i = c("c","d","a"), l = 7

I am having trouble with basic installing packages and library calling

雨燕双飞 提交于 2021-02-11 14:34:58
问题 When I execute install.packages("dplyr") I get Error: invalid version specification ‘NA’ In addition: Warning message: In utils:::packageDescription(packageName, fields = "Version") : no package 'knitr' was found Then I call the library and it obviously doesn't work either - library(dplyr) Error: package or namespace load failed for ‘dplyr’: .onLoad failed in loadNamespace() for 'pillar', details: call: utils::packageVersion("vctrs") error: package ‘vctrs’ not found In addition: Warning

Filter a piped df within ggplot

末鹿安然 提交于 2021-02-11 13:53:29
问题 I am using a dplyr pipeline to clean my df then feed directly into a ggplot. However, I want to plot only one group at a time, so I need to filter to just that group. The problem is, I want the scales to remain constant as if all groups are present. Is it possible to further filter a piped df inside the ggplot() commands? Ex below. # create df set.seed(1) df <- data.frame(matrix(nrow=100,ncol=5)) colnames(df) <- c("year","group","var1","var2","var3") df$year <- rep(1:4,each=25) df$group <-

Replace values in a column with specific row value from same column using loop

落爺英雄遲暮 提交于 2021-02-11 13:50:09
问题 I have data obtained from a survey that lists the recipient's name and whether or not they selected a specific county in the state. The survey structure outputs an off for any county not selected and an for the selected county. The state has about 100 counties so there end up being a lot of columns that really correspond to the same question. What I am looking to do is replace any cells with on with the county name and any cells with off with a blank. From there I can basically unite many

Tidy Evaluation not working with mutate and stringr

守給你的承諾、 提交于 2021-02-11 13:43:16
问题 I've trying to use Tidy Eval and Stringr togheter inside a mutate pipe, but every time I run it it gives me an undesirable result. Instead of changing the letter 'a' for the letter 'X', it overwrite the entire vector with the column name, as you can see in the example below, that uses the IRIS dataset. text_col="Species" iris %>% mutate({{text_col}} := str_replace_all({{text_col}}, pattern = "a", replacement = "X")) result: structure(list(Sepal.Length = c(5.1, 4.9, 4.7, 4.6, 5, 5.4, 4.6, 5, 4

Writing a custom case_when function to use in dplyr mutate using tidyeval

萝らか妹 提交于 2021-02-11 13:32:12
问题 I'm trying to write a custom case_when function to use inside dplyr. I've been reading through the tidyeval examples posted in other questions, but still can't figure out how to make it work. Here's a reprex: df1 <- data.frame(animal_1 = c("Horse", "Pig", "Chicken", "Cow", "Sheep"), animal_2 = c(NA, NA, "Horse", "Sheep", "Chicken")) translate_title <- function(data, input_col, output_col) { mutate(data, !!output_col := case_when( input_col == "Horse" ~ "Cheval", input_col == "Pig" ~ "Рorc",

R: converting tidyverse to dplyr/reshape2 for plots

China☆狼群 提交于 2021-02-11 13:13:25
问题 In a previous post, a user showed me how to to plot longitudinal data in R. Here is the code: library(ggplot2) Data <- data.frame( "ID" = c("ABC111", "ABC111", "ABC111", "ABC111", "ABC112", "ABC112", "ABC112", "ABC113", "ABC113", "ABC114", "ABC115"), "color" = c("red", "red", "red", "red", "blue", "blue", "blue", "green", "green", "black", "yellow"), "start_date" = c("2005/01/01", "2006/01/01", "2007/01/01", "2008/01/01", "2009/01/01", "2010/01/01", "2011/01/01", "2012/01/01", "2013/01/01",

R: converting tidyverse to dplyr/reshape2 for plots

这一生的挚爱 提交于 2021-02-11 13:12:01
问题 In a previous post, a user showed me how to to plot longitudinal data in R. Here is the code: library(ggplot2) Data <- data.frame( "ID" = c("ABC111", "ABC111", "ABC111", "ABC111", "ABC112", "ABC112", "ABC112", "ABC113", "ABC113", "ABC114", "ABC115"), "color" = c("red", "red", "red", "red", "blue", "blue", "blue", "green", "green", "black", "yellow"), "start_date" = c("2005/01/01", "2006/01/01", "2007/01/01", "2008/01/01", "2009/01/01", "2010/01/01", "2011/01/01", "2012/01/01", "2013/01/01",

Facet wrap of a lollipop plot

一世执手 提交于 2021-02-11 12:49:35
问题 I'm trying to make multiple lollipop plots using a facet wrap, like in the third code block / example and picture below on this page. However, I can't get the code example to work. Can you please help me see where it is written incorrectly (if at all)? The data: set.seed(1) data <-as.data.frame(matrix( sample( 2:20 , 40 , replace=T) , ncol=10)) colnames(data) <- c("math" , "english" , "biology" , "music" , "R-coding", "data-viz" , "french" , "physic", "statistic", "sport" ) data <-rbind(rep