r

how to make stacked barplot with defined horizontal borders for each bar

风格不统一 提交于 2021-02-17 06:26:26
问题 I have data that i want to show in barplot in a way that i could'nt figure out how. Hope you can help me with this! My table consists of 4 columns: cluster (0:6), IgG_Status (mild_high, mild_low,Severe_High), patient (1-16) and value (normalized value per each cluster). These are the lines of code i'm using now to create a barplot of the sum of values for each cluster, divided to IgG_Status (dodged style). ggplot(mat, aes(x= cluster, fill= IgG_status, group=IgG_status)) + geom_bar(aes(weight

can i make a simple regression from matrix?

我怕爱的太早我们不能终老 提交于 2021-02-17 06:26:26
问题 data11 <- matrix(c(f11, p3, a3, b1, c1, d1), ncol = 6) dimnames(data11) <- list(c('2015/16', '2016/17', '2017/18', '2018/19', '2019/20'), c('GPA', 'Sex', 'Fulltime', 'Indigenous', 'Co-op', 'International')) I created a matrix from data. GPA Sex Fulltime Indigenous Co-op International 2015/16 2.738711 0.1957311 0.5429625 0.008433362 0.4104236 0.2378208 2016/17 2.799184 0.1922954 0.5640596 0.01018903 0.420968 0.2330071 2017/18 2.842297 0.2017633 0.5600541 0.008940075 0.4422708 0.2392785 2018/19

How to remove non UTF-8 characters from text

放肆的年华 提交于 2021-02-17 06:25:07
问题 I need help removing non UTF-8 character from my word cloud. So far this is my code. I've tried gsub and removeWords and they are still there in my word cloud and I do not know what to do to get rid of them. Any help would be appreciated. Thank you for your time. txt <- readLines("11-0.txt") corpus = VCorpus(VectorSource(txt)) gsub("’","‘","",txt) corpus = tm_map(corpus, content_transformer(tolower)) corpus = tm_map(corpus, removeWords, stopwords("english")) corpus = tm_map(corpus,

How to view all xml_nodeset class object (output of rvest::html_nodes) in R?

北城以北 提交于 2021-02-17 06:25:06
问题 If we create an object of class xml_nodes using rvest 's html_nodes() , how can we view all of the output in the R console Example library(rvest) library(dplyr) # Generate some sample html a <- rep("<p></p>", 200) %>% paste0(collapse="") a <- a %>% read_html %>% html_nodes("p") a %>% length # 200 # But only see first 20 (want to see all) 回答1: You can type in print.AsIs(a) to print the entire list. (Truncated for brevity.) library(rvest) #> Loading required package: xml2 library(dplyr) #> #>

R - Replace multiple patterns with multiple ids

雨燕双飞 提交于 2021-02-17 06:22:08
问题 This was partially already tackled in others posts but unfortunately I could not make it run properly on my side. I have a data frame full of texts, and there are certain words that I want replaced by a unique name. So, if we see the table bellow, I would want to replace each of the words "Banana Apple Tomato" by the word "Fruit" (the word Fruit can show up multiple times, that is ok) I also want to replace "Cod Pork Beef" by the word "Animals" I have a full excel file where this mapping was

difference between the two ways of using aes in ggplot?

谁说胖子不能爱 提交于 2021-02-17 06:21:25
问题 I recently started learning R but am confused with the aes feature in ggplot2. I have seen two different places where aes is placed in the code. ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy)) ggplot(mpg, aes(x = displ, y = hwy)) + geom_point() What is the difference between the two? 回答1: Can't find a dupe, so here's an answer: Aesthetics specified in ggplot() are inherited by subsequent layers. Aesthetics specified in particular layers are specific only to that layer. Here

What package in R is used to calculate non-zero null hypothesis p-values on linear models?

a 夏天 提交于 2021-02-17 06:17:06
问题 The standard summary(lm(Height~Weight)) will output results for the hypothesis test H0: Beta1=0, but if I am interested in testing the hypothesis H0: B1=1 is there a package that will produce that p-value? I know I can calculate it by hand and I know I can "flip the confidence interval" for a two tailed test (test a 95% hypothesis by seeing if the 95% confint contains the point of interest), but I am looking for an easy way to generate the p-values for a simulation study. 回答1: You can use

What package in R is used to calculate non-zero null hypothesis p-values on linear models?

一笑奈何 提交于 2021-02-17 06:17:05
问题 The standard summary(lm(Height~Weight)) will output results for the hypothesis test H0: Beta1=0, but if I am interested in testing the hypothesis H0: B1=1 is there a package that will produce that p-value? I know I can calculate it by hand and I know I can "flip the confidence interval" for a two tailed test (test a 95% hypothesis by seeing if the 95% confint contains the point of interest), but I am looking for an easy way to generate the p-values for a simulation study. 回答1: You can use

Can someone please explain me this code? especially the role of “function x and [[x]]”?

旧巷老猫 提交于 2021-02-17 06:10:14
问题 This is the code in R and I'm having trouble understanding the role of function(x) and qdata[[x]] in this line of code. Can someone elaborate me this piece by piece? I didn't write this code. Thank you outs=lapply(names(qdata[,12:35]), function(x) hist(qdata[[x]],data=qdata,main="Histogram of Quality Trait", xlab=as.character(x),las=1.5)$out) 回答1: This code generate a series of histograms, one for each of columns 12 to 35 of dataframe qdata. The lapply function iterates over the columns. At

Add rep vector to dataframe with uneven total rows

空扰寡人 提交于 2021-02-17 06:05:24
问题 I'm trying to find a way of automating a large dataset to add two factors but the data may contain uneven rows. I've tried to do this with the 'rep' function but this will only work if the data frame has even numbers. x<-c(1,3,5,7,9) y<-c(2,4,6,8,10) df<-data.frame(x,y) df$state<-factor(rep(1:2)) Error in `$<-.data.frame`(`*tmp*`, state, value = 1:2) : replacement has 2 rows, data has 5 How do I get the data.frame to recycle 1 into row 5 instead of an error? 回答1: rep() 's length.out argument