r

R Custom Color Scale for Plotting

人盡茶涼 提交于 2021-02-10 13:29:28
问题 I am attempting to create a custom scale that will better display the data I have. For the first plot, the data was relatively uniform, falling in between 0 and 3. However, for my second dataset, the majority of the data is less than 100, and approximately 90% of the data is under 1000. (plots at bottom) The column with the values I am trying to plot is named 'data1', and the values are whole numbers ranging from 0-10000. I tried applying the code on https://gis.stackexchange.com/questions

How to get predictions for each fold in 10-fold cross-validation of the best tuned hyperparameters using caret package in r?

心不动则不痛 提交于 2021-02-10 13:28:16
问题 I was trying to run SVM model using 10-fold cross-validation with 3 repeats using the caret package in R. I want to get the prediction results of each fold using the best tuned hyperparameters. I am using the following code # Load packages library(mlbench) library(caret) # Load data data(BostonHousing) #Dividing the data into train and test set set.seed(101) sample <- createDataPartition(BostonHousing$medv, p=0.80, list = FALSE) train <- BostonHousing[sample,] test <- BostonHousing[-sample,]

Error when estimating CI for GLMM using confint()

寵の児 提交于 2021-02-10 13:27:31
问题 I have a set of GLMMs fitted with a binary response variable and a set of continuous variables, and I would like to get confidence intervals for each model. I've been using confint() function, at 95% and with the profile method, and it works without any problems if it is applied to a model with no interactions. However, when I apply confint() to a model with interactions (continuous*continuous), I've been getting this error: m1CI <- confint(m1, level=0.95, method="profile") Error in zeta

Make two vectors of different lengths equal in length

杀马特。学长 韩版系。学妹 提交于 2021-02-10 13:17:09
问题 I have two vectors of different lenghts. How can I start both series so their ends concide. x<-c(1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6) y<-c(1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4) I do it with the code below but I guess there must be a more elegant way x<-x[((length(x)-length(y))+1):length(x)] x [1] 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 y [1] 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 回答1: Use tail , and min to determine the shortest vector: shortest <- min(length(x), length(y)) y <- tail(y, shortest) x <

(Rbplpapi) Get more than 7 months of intraday data

。_饼干妹妹 提交于 2021-02-10 13:15:56
问题 Good afternoon. The task I want to perform is actually quite simple. Using R, connected to Bloomberg with the Rbplpapi package, I want to get as more as possible of intraday (1min) data for the S&P 500.I tried the following code: library("Rblpapi") con = blpConnect() start_date = "01/01/1999 00:00:00" last_date = "07/12/2019 00:00:00" start_date = as.POSIXct(start_date, format="%m/%d/%Y %H:%M:%S",tz="EST") last_date = as.POSIXct(last_date, format="%m/%d/%Y %H:%M:%S",tz="EST") data_spx =

(Rbplpapi) Get more than 7 months of intraday data

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-10 13:14:09
问题 Good afternoon. The task I want to perform is actually quite simple. Using R, connected to Bloomberg with the Rbplpapi package, I want to get as more as possible of intraday (1min) data for the S&P 500.I tried the following code: library("Rblpapi") con = blpConnect() start_date = "01/01/1999 00:00:00" last_date = "07/12/2019 00:00:00" start_date = as.POSIXct(start_date, format="%m/%d/%Y %H:%M:%S",tz="EST") last_date = as.POSIXct(last_date, format="%m/%d/%Y %H:%M:%S",tz="EST") data_spx =

Add text to plot with facetted bar chart

让人想犯罪 __ 提交于 2021-02-10 13:10:25
问题 My question is related to this question. I want "2014" in the 4-year facet. I tried to repeat but my code doesn't give what I want. Annotating text on individual facet in ggplot2 This is my data structure(list(Rot = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("2-year", "3-year", "4-year"), class = "factor"), Rot.Herb = structure(c(3L, 3L, 4L, 4L, 13L, 13L, 14L, 14L, 5L,

Direct labels puts labels at wrong place

。_饼干妹妹 提交于 2021-02-10 12:55:51
问题 I'm trying to do a plot with ggplot2 and trying to put labels at the right place on mean trajectories with confidence regions. Since I cannot share my data, I created a reproducible example: set.seed(456) library(ggplot2) library(directlabels) time<-1:25 df2<-data.frame(time,value=runif(2500),group=as.factor(c(rep('Alpha',1250),rep('Beta',1250)))) ggplot(df2, aes(x=time, y=value,group=group,colour=group))+ stat_summary(geom="ribbon", fun.data=mean_cl_normal,fun.args=list(conf.int=0.95), fill=

Subset spatial points with a polygon

人走茶凉 提交于 2021-02-10 12:50:13
问题 I have a SpatialPolygonsDataFrame (spolydf) and a SpatialPointsDataFrame (spointdf). The layers have different extents, but overlap. I can select points that fall within the polygon using fall.within.poly <- spointdf[spolydf,] How do I select points that fall outside the polygon? have tried fall.outside.poly <- spointdf[-spolydf,] but doesn't work. I'm mmissing something simple - any help please. 回答1: It's a bit late but I had the same issue today so I though that I would post my solution

Filter one column by matching to another column

雨燕双飞 提交于 2021-02-10 12:43:08
问题 I have a data frame with a variable containing elements to drop if they match to an element in another variable - see a small example below: df <- data.frame(pair = c(1, 1, 2, 2, 3, 3), animal = rep(c("dog", "cat"), 3), value = seq(1, 12, 2), drop = c("no", "no", "dog", "dog", "cat", "cat")) pair animal value drop 1 1 dog 1 no 2 1 cat 3 no 3 2 dog 5 dog 4 2 cat 7 dog 5 3 dog 9 cat 6 3 cat 11 cat I'm trying to want to filter the data frame according to whether the value of animal matches the