r

R - reformat P value in ggplot using 'stat_compare_means'

流过昼夜 提交于 2021-02-18 19:00:28
问题 I want to plot the p values to each panel in a faceted ggplot. If the p value is larger than 0.05, I want to display the p value as it is. If the p value is smaller than 0.05, I want to display the value in scientific notation (i.e, 0.0032 -> 3.20e-3; 0.0000425 -> 4.25e-5). The code I wrote to do this is: p1 <- ggplot(data = CD3, aes(location, value, color = factor(location), fill = factor(location))) + theme_bw(base_rect_size = 1) + geom_boxplot(alpha = 0.3, size = 1.5, show.legend = FALSE)

How Do I Set.Seed for simulation in R to attain reproducibility on Windows OS

走远了吗. 提交于 2021-02-18 18:59:48
问题 I have a simulation done with the below function in R : ## Load packages and prepare multicore process library(forecast) library(future.apply) plan(multisession) library(parallel) library(foreach) library(doParallel) n_cores <- detectCores() cl <- makeCluster(n_cores) registerDoParallel(cores = detectCores()) set.seed(1) bootstrap1 <- function(n, phi){ ts <- arima.sim(n, model = list(ar=phi, order = c(1, 1, 0)), sd = 1) #ts <- numeric(n) #ts[1] <- rnorm(1) #for(i in 2:length(ts)) # ts[i] <- 2

Can not use dynamic variable names with dplyr in r

寵の児 提交于 2021-02-18 18:57:27
问题 I see the answers on this website, but it can not solve my problem. What I want is that use dynamic variable names both on LHS and RHS within summarize . This is a simple example to show what I have tried: why I use paste0('carb') not use carb directly is that on the position( paste0('carb') ) is a dynamic variable like this paste0('temp', n) and n is a series of numbers in my real situation. library(dplyr) sumay1 <- mtcars %>% group_by(cyl) %>% summarise(!!paste0('carb', 100) := mean(paste0(

R Markdown - Hyperlink outside Rmd file

一曲冷凌霜 提交于 2021-02-18 18:56:52
问题 I am wondering how we can define a hyperlink for R markdown outside Rmd file. Defining a hyperlink inside Rmd file is as easy as typing [hyperlink lable](actual link); but, if on the Rmd file, I am calling some other r-file (e.g., a function) that generates an address to a file, is there a way to transfer this information back to Rmd file to generate a hyperlink there? Please see example below for more clarification: Inside Rmd file: myFun( with some input) Inside myFun: myFun <- function(

How to count matches between a vector and dataframe of sequence coordinates?

梦想与她 提交于 2021-02-18 18:55:42
问题 Given a data table with start and end coordinates for sequences of integers: set.seed(1) df1 <- data.table( START = c(seq(1, 10000000, 10), seq(1, 10000000, 10), seq(1, 10000000, 10)), END = c(seq(10, 10000000, 10), seq(10, 10000000, 10), seq(10, 10000000, 10)) And a vector of integers: vec1 <- sample(1:100000, 10000) How can I count the number of integers in vec1 that are within the start and end coordinates of each sequence in df1? I am currently using a for loop: COUNT <- rep(NA, nrow(df1)

Issue in DocumentTermMatrix with corpus in German

余生颓废 提交于 2021-02-18 18:53:42
问题 I created a corpus in R using package tm specifying language and encoding as follows: de_DE.corpus <- Corpus(VectorSource(de_DE.sample), readerControl = list(language="de_DE",encoding = "UTF_8")) de_DE.corpus[36]$content de_DE.dtm <- DocumentTermMatrix(de_DE.corpus,control = list (encoding = 'UTF-8')) inspect(de_DE.dtm[, grepl("grÃ", de_DE.dtm$dimnames$Terms)]) inspect(de_DE.dtm[36, ]) If I see the content in de_DE.corpus[36]$content of document 36 which has 'ü' the text is shown correctly. e

RSelenium: Scraping a dynamically loaded page that loads slowly

蹲街弑〆低调 提交于 2021-02-18 18:39:50
问题 I'm not sure if it is because my internet is slow, but I'm trying to scrape a website that loads information as you scroll down the page. I'm executing a script that goes to the end of the page, and waits for the Selenium/Chrome server to load the additional content. The server does update and load the new content, because I am able to scrape information that wasn't on the page originally and the new content shows up on the chrome viewer, but it only updates once. I set a Sys.sleep() function

Error in Shiny deployment on shinyapps.io

可紊 提交于 2021-02-18 18:15:11
问题 I got a Shiny App that works fine on my PC, but once I deploy on shinyapps.io it shows the following error on the web browser: And the following error on the Deployment Console: Warning message: In value[[3L]](cond) : Failed to parse C:/Users/david.jorquera/AppData/Local/Temp/RtmpSOqdYV/file13849671673/app.R ; dependencies in this file will not be discovered. If you need the exact excel file I'm using I would happily attach it if you tell me how to do it (sorry, haven't figure that out yet).

add a second geom_tile layer in ggplot

▼魔方 西西 提交于 2021-02-18 18:14:10
问题 I have a relatively simple heatmap using geom_tile in ggplot2. It's just a small matrix of continuous data as colored boxes ( df1 ) and I'd like to overlay a second, logical geom_tile that outlines the TRUE values ( df2 ). Can such a thing be done? I know that adding two heatmaps together seems like it would be ugly but these are small and pretty simple affairs. library(ggplot2) n <- 4 df1 <- data.frame(x = rep(letters[1:n], times = n), y = rep(1:n, each = n), z = rnorm(n ^ 2)) df2 <- data

Plot a table of separate data below a ggplot2 graph that lines up on the X axis

自闭症网瘾萝莉.ら 提交于 2021-02-18 18:11:59
问题 I'm looking to create a plot that contains a simple multi-line ggplot2 graph with a table of separate (but relevant) data below the graph that lines up by the X axis of the graph. The data table's column names do match the x axis of the graph (hours 1 to 24), but one column is dedicated to necessary row names. Here are the graph and the data table separately: Data table is cut off at hour 16 for brevity, but does extend to 24. I've been attempting different solutions in gridExtra all morning