r

Remove Gaps Between Bars in Plotly

送分小仙女□ 提交于 2021-02-19 05:30:15
问题 I am trying to create a Marimekko chart in R using Plotly. Essentially, this is just a stacked, variable-width bar chart with both bars directly adjacent to one another. Currently, my attempt looks like this: The code to create it is here: bar.test <- plot_ly(type = "bar") %>% layout(title = paste0("Newark Charter vs District BTO Makeup"), xaxis = list(title = ""), yaxis = list(title = "Percent BTO", tickformat = "%")) %>% add_trace(x = ~test1$sch.type, y = ~test1$y, width = ~test1$width,

Remove Gaps Between Bars in Plotly

左心房为你撑大大i 提交于 2021-02-19 05:30:09
问题 I am trying to create a Marimekko chart in R using Plotly. Essentially, this is just a stacked, variable-width bar chart with both bars directly adjacent to one another. Currently, my attempt looks like this: The code to create it is here: bar.test <- plot_ly(type = "bar") %>% layout(title = paste0("Newark Charter vs District BTO Makeup"), xaxis = list(title = ""), yaxis = list(title = "Percent BTO", tickformat = "%")) %>% add_trace(x = ~test1$sch.type, y = ~test1$y, width = ~test1$width,

Flow duration curve using facet_wrap of ggplot in R?

混江龙づ霸主 提交于 2021-02-19 05:27:05
问题 I am using fdc of hydroTSM package . I have three data.frame and i would like to construct Flow duration curves (FDC) of the data.frame using facet_wrap functionality of ggplot to have the plots in three rows and one column . the following will produce FDC curves for DF1 . library(tidyverse) library(hydroTSM) library(gridExtra) DF1 = data.frame(Ob = runif(1000,0,500), A = runif(1000,0,700), B = runif(1000,2,800)) DF2 = data.frame(Ob = runif(1000,0,500), A = runif(1000,0,700), B = runif(1000,2

Flow duration curve using facet_wrap of ggplot in R?

早过忘川 提交于 2021-02-19 05:26:37
问题 I am using fdc of hydroTSM package . I have three data.frame and i would like to construct Flow duration curves (FDC) of the data.frame using facet_wrap functionality of ggplot to have the plots in three rows and one column . the following will produce FDC curves for DF1 . library(tidyverse) library(hydroTSM) library(gridExtra) DF1 = data.frame(Ob = runif(1000,0,500), A = runif(1000,0,700), B = runif(1000,2,800)) DF2 = data.frame(Ob = runif(1000,0,500), A = runif(1000,0,700), B = runif(1000,2

Caret returns different predictions with caret train object than it does with the extracted final model

落花浮王杯 提交于 2021-02-19 05:25:47
问题 I prefer to use caret when fitting models because of its relative speed and preprocessing capabilities. However, I'm slightly confused on how it makes predictions. When comparing predictions made directly from the train object and predictions made from the extracted final model, I'm seeing very different numbers. The predictions from the train object appear to be more accurate. library(caret) library(ranger) x1 <- rnorm(100) x2 <- rbeta(100, 1, 1) y <- 2*x1 + x2 + 5*x1*x2 data <- data.frame

Barplot customization

一个人想着一个人 提交于 2021-02-19 05:18:46
问题 So I have this data table AA BB CC DD W1 3.5 3.5 3.4 3.5 w2 3.4 3.7 3.6 3.5 w3 3.5 3.4 3.5 3.5 w4 3.5 3.4 3.5 3.5 w5 3.5 3.4 3.5 3.5 w6 3.5 3.4 3.5 3.5 w7 3.5 3.4 3.5 3.5 w8 3.5 3.4 3.5 3.5 and code qw<-barplot(as.matrix(t(tabela.matrix1)), beside=TRUE, col=c("yellow", "cornflowerblue", "yellowgreen","orchid4")) text(qw, 0, round(as.matrix(t(tabela.matrix1)), 1),cex=1,pos=3,srt=90) #legend("bottom", # c("AA","BB","CC", "DD"), # fill=terrain.colors(4) ) that outputs this barplot Now I would

Melting two sets of columns from wide- to long-form using reshape2 [duplicate]

吃可爱长大的小学妹 提交于 2021-02-19 05:17:05
问题 This question already has answers here : Reshaping multiple sets of measurement columns (wide format) into single columns (long format) (7 answers) Closed 4 years ago . I am trying to add a time-varying predictor to a long-form dataframe using reshape2::melt but I was wondering if there was a faster way to do it. Here is the toy data in wide form. There are three measures of an outcome variable (session1, session2, and session3) taken at different visits/time points. The duration between

Remove duplicate values across a few columns but keep rows

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-19 05:14:58
问题 I have a dataframe that looks like this: dat <- data.frame(id=1:6, z_1=c(100,290,38,129,0,290), z_2=c(20,0,0,0,0,290), z_3=c(0,0,38,0,0,98), z_4=c(0,0,38,127,38,78), z_5=c(23,0,25,0,0,98), z_6=c(100,0,25,127,0,9)) dat id z_1 z_2 z_3 z_4 z_5 z_6 1 1 100 20 0 0 23 100 2 2 290 0 0 0 0 0 3 3 38 0 38 38 25 25 4 4 129 0 0 127 0 127 5 5 0 0 0 38 0 0 6 6 290 290 98 78 98 9 I want to remove duplicate values of z_x across each row, replacing any duplicates with either a 0 or NA , but leaving the rows &

Remove duplicate values across a few columns but keep rows

陌路散爱 提交于 2021-02-19 05:14:05
问题 I have a dataframe that looks like this: dat <- data.frame(id=1:6, z_1=c(100,290,38,129,0,290), z_2=c(20,0,0,0,0,290), z_3=c(0,0,38,0,0,98), z_4=c(0,0,38,127,38,78), z_5=c(23,0,25,0,0,98), z_6=c(100,0,25,127,0,9)) dat id z_1 z_2 z_3 z_4 z_5 z_6 1 1 100 20 0 0 23 100 2 2 290 0 0 0 0 0 3 3 38 0 38 38 25 25 4 4 129 0 0 127 0 127 5 5 0 0 0 38 0 0 6 6 290 290 98 78 98 9 I want to remove duplicate values of z_x across each row, replacing any duplicates with either a 0 or NA , but leaving the rows &

Highlight / Draw a box around some of the plots when using `facet_grid` in ggplot2

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-19 05:01:32
问题 I am creating a matrix of plots similar to ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_grid(rows = vars(cyl), cols = vars(drv)) Now, I would like to have some way to highlight some of the individual plots, say the ones where cyl is 5 or 6, and drv is f . So, ideally, this might look like this: But I would also be happy with those panels having a different look by setting ggtheme to classic or similar. However, it is very unclear to me how I can modify individually selected plots