r

How do you set the color palette so that it starts with the darkest color, where older data being lighter than current

本小妞迷上赌 提交于 2021-02-19 07:37:27
问题 I'm plotting a correlation scatter plot, where my data frame has time data and the start year is arbitrary. In this case now I have the following R code ## Set seed for randomness in dummy data: ## set.seed(123) ## Create data frame: ## df.Data <- data.frame(date = seq(as.Date('2019-01-01'), by = '1 day', length.out = 650), DE = rnorm(650, 2, 1), AT = rnorm(650, 5, 2)) corPearson <- cor.test(x = df.Data$DE, y = df.Data$AT, method = "pearson") df.Data$year <- format(as.Date(df.Data$date), '%Y'

Parallel Processing for Setting Seed in R

此生再无相见时 提交于 2021-02-19 07:36:06
问题 I Have an R code that helps me to know at what seed when I use arima.sim() function to simulate ARIMA(1, 0, 0) it will actually simulate ARIMA of order 1, 0, 0 when auto.arima() function is employed for a check. MWE library(forecast) SEED_vector <- 1:10 arima_order_results <- data.frame() flag <- TRUE i <- 1 seed_out <- c() while(flag){ set.seed(SEED_vector[i]) ar1 <- arima.sim(n = 20, model=list(ar=0.8, order = c(1, 0, 0)), sd = 1) ar2 <- auto.arima(ar1, ic = "aicc") if(all(arimaorder(ar2)=

Configuration failed to find libgit2 library

江枫思渺然 提交于 2021-02-19 07:34:19
问题 When attempting to install the R devtools package (on Linux Mint, 19.3 & R 4.0.2),I receive this error. In the ANTICONF section the message offers some suggestions for what I should do, but being new to Linux I don't understand how to implement the instructions, and my search of the internet has not yielded fruit. Could someone offer guidance on the commands/steps I need to take to install libgit2 or resolve this issue? > install.packages("devtools") Installing package into ‘/home/xilliam/R

R shiny remove UI keeps the label

你。 提交于 2021-02-19 07:34:10
问题 I am calling shiny removeUi() for an textInput, however, only the input section gets removed and not the label. See code and image below: clearElements <- function (dat) { observe({ for (el in dat) { id <- strsplit(el,substring(el, nchar(el)-8, nchar(el)))[[1]] print(id) removeElement(id) } }) } removeElement <- function (el_id) { removeUI( selector = paste0("#", el_id), multiple = TRUE, immediate = TRUE, session ) } Here is the visual result: 回答1: The accepted answer does not work. You need

Replace multiple values using a reference table

百般思念 提交于 2021-02-19 07:34:09
问题 I’m cleaning a data base, one of the fields is “country” however the country names in my data base do not match the output I need. I though of using str_replace function but I have over 50 countries that need to be fix, so it’s not the most efficient way. I already prepared a CSV file with the original country input and the output I need for reference. Here is what I have so far: library(stringr) library(dplyr) library(tidyr) library(readxl) database1<- read_excel("database.xlsx") database1

scale_colour_gradient vs. scale_fill_gradient in ggplot2

柔情痞子 提交于 2021-02-19 07:18:07
问题 I am an absolute beginner in ggplot2 and trying to draw beautiful figures using this package. I am going through the manual and I didn't understand the difference between scale_colour_gradient() vs. scale_fill_gradient() In my analysis, I will use "hypothesis" for observations because I am unsure about my conclusions. Here's the original code that worked for me: Experiment 1 erupt <- ggplot(faithfuld, aes(waiting, eruptions, fill = density)) + geom_raster() erupt Hypothesis: It plots the

rename list of dataframe columns to mimic joined suffixes

青春壹個敷衍的年華 提交于 2021-02-19 07:18:07
问题 I have a list of dataframes: dd <- list() dd$data <- list( ONE = data.frame(inAll = c(1.1,1.2,1.3), inAll_2 = c(1.4,1.5,1.6)), TWO = data.frame(inAll = c(2.1,2.2,2.3), inAll_2 = c(2.4,2.5,2.6)), THREE = data.frame(inAll = c(3.1,3.2,3.3), inAll_2 = c(3.4,3.5,3.6)), FOUR = data.frame(inAll = c(4.1,4.2,4.3), inAll_2 = c(4.4,4.5,4.6)), FIVE = data.frame(inAll = c(5.1,5.2,5.3), inAll_2 = c(5.4,5.5,5.6)), SIX = data.frame(inAll = c(6.1,6.2,6.3), inAll_2 = c(6.4,6.5,6.6)) ) And then reduce those

R: asynchronous parallel lapply

隐身守侯 提交于 2021-02-19 07:14:58
问题 The simplest way I've found so far to use a parallel lapply in R was through the following example code: library(parallel) library(pbapply) cl <- makeCluster(10) clusterExport(cl = cl, {...}) clusterEvalQ(cl = cl, {...}) results <- pblapply(1:100, FUN = function(x){rnorm(x)}, cl = cl) This has a very useful feature of providing a progress bar for the results, and is very easy to reuse the same code when no parallel computations are needed, by setting cl = NULL . However, one issue that I've

R Leaflet PopupGraph - addPopupGraphs on map_marker_click

孤者浪人 提交于 2021-02-19 07:11:02
问题 I would like to open a popup with a unique plot for each of my marker in it on a map_marker_click using r leaflet and the leafpop library. For each point when the user click on them the plot to display is computed. Below is a reproductible code but it doesn't return any error. Any ideas? library(tidyverse) library(ggplot2) library(shiny) library(leaflet) library(leafpop) id <- c(1,1,1,1,2,2,3,3,3,4) lat <- c(49.823, 49.823, 49.823, 49.823, 58.478, 58.478, 57.478 , 57.478 , 57.478, 38.551) lng

R Leaflet PopupGraph - addPopupGraphs on map_marker_click

≯℡__Kan透↙ 提交于 2021-02-19 07:09:13
问题 I would like to open a popup with a unique plot for each of my marker in it on a map_marker_click using r leaflet and the leafpop library. For each point when the user click on them the plot to display is computed. Below is a reproductible code but it doesn't return any error. Any ideas? library(tidyverse) library(ggplot2) library(shiny) library(leaflet) library(leafpop) id <- c(1,1,1,1,2,2,3,3,3,4) lat <- c(49.823, 49.823, 49.823, 49.823, 58.478, 58.478, 57.478 , 57.478 , 57.478, 38.551) lng