geom-bar

Regarding factoring in R

99封情书 提交于 2021-02-20 03:51:43
问题 I have this code where currently I am displaying for 2 patients but I have to group the 3 records and display them for more than 15 patients. Currently I am factoring for each patients as below but is there any way to use factor with grep so that my factor won't become so tedious pat_paste_c<-factor(pat_paste_c,levels=c('Pat_1_IT-6','Pat_1_IT-7','Pat_1_IT-8',"Pat_2_IT-6","Pat_2_IT-7","Pat_2_IT-8"),ordered = TRUE) c<- data.frame(Var=character(), Pat_1=double(), Pat_2=double(), stringsAsFactors

scale_fill_manual is not working in geom_bar

让人想犯罪 __ 提交于 2021-02-16 13:15:14
问题 I'm trying to change the color in a barplot in ggplot2 using scale_fill_manual, but for some reason only works if i use the fill option inside aesthetics. I made an example: library(ggplot2) library(dplyr) iris %>% ggplot(aes(x=Sepal.Width,y=Sepal.Length))+ geom_bar(stat="identity") + scale_fill_manual(values='lightblue') Here is the result, no changing in the color: Now, using the fill option inside aesthetics, it works: iris %>% ggplot(aes(x=Sepal.Width,y=Sepal.Length, fill=factor(2) ))+

scale_fill_manual is not working in geom_bar

柔情痞子 提交于 2021-02-16 13:15:09
问题 I'm trying to change the color in a barplot in ggplot2 using scale_fill_manual, but for some reason only works if i use the fill option inside aesthetics. I made an example: library(ggplot2) library(dplyr) iris %>% ggplot(aes(x=Sepal.Width,y=Sepal.Length))+ geom_bar(stat="identity") + scale_fill_manual(values='lightblue') Here is the result, no changing in the color: Now, using the fill option inside aesthetics, it works: iris %>% ggplot(aes(x=Sepal.Width,y=Sepal.Length, fill=factor(2) ))+

ggplot2 order categorical stacked bars by proportions of y-axis

自古美人都是妖i 提交于 2021-02-15 04:53:05
问题 I have a data frame with categorical x-axis called Category and the yaxis is the Abundance, colored by Sequence. For each Category I am trying to reorder the stacks by the Abundance, so that it is easily visualized which sequence has the highest proportion at the bottom, to the lowest proportion at the top. Currently, I can make a bar graph like this: s<-"Sequence Abundance Category CAGTG 0.8 A CAGTG 0.2 B CAGTG 0.6 C CAGTG 0.3 D CAGTG 0.1 E GGGAC 0.1 A GGGAC 0.1 B GGGAC 0.3 C GGGAC 0.6 D

ggplot2 order categorical stacked bars by proportions of y-axis

给你一囗甜甜゛ 提交于 2021-02-15 04:51:37
问题 I have a data frame with categorical x-axis called Category and the yaxis is the Abundance, colored by Sequence. For each Category I am trying to reorder the stacks by the Abundance, so that it is easily visualized which sequence has the highest proportion at the bottom, to the lowest proportion at the top. Currently, I can make a bar graph like this: s<-"Sequence Abundance Category CAGTG 0.8 A CAGTG 0.2 B CAGTG 0.6 C CAGTG 0.3 D CAGTG 0.1 E GGGAC 0.1 A GGGAC 0.1 B GGGAC 0.3 C GGGAC 0.6 D

second y-axis with other scale [duplicate]

ぐ巨炮叔叔 提交于 2021-02-08 10:28:50
问题 This question already has answers here : ggplot with 2 y axes on each side and different scales (17 answers) Closed 4 days ago . I created a barchart with ggplot2 geom_bar and want to have two metrics in the bars. I used melt to do so. However, I now need a second y-axis with another scale, because the numbers of the two metrics are too different. In the following the dataframe and the code I used: df <- data.frame(categories = c("politics", "local", "economy", "cultural events", "politics",

stacked barplot with aggregated data (ggplot2)

隐身守侯 提交于 2021-02-08 08:21:30
问题 I have some major problems with ggplot2. Even though it might be a very easy question to you I couldnt manage yet to get it right (I have read a ggplot2-book and was looking on stackoverflow as well). Orginally there was a dataset consisting of a factor variable (country) and a dichotomous variable. Unfortunately I dont have my data in this extended format myself: I have two variables "var1" and "var2". var1 gives the number of cases in the original dataset where a certain condition is true

Barplot with ggplot 2 of two categorical variable facet_wrap according a third variable displayng percentage

∥☆過路亽.° 提交于 2021-02-07 10:16:14
问题 I would like to barplot in ggplot2 a categorical variable grouped according a second categorical variable and use facet_wrap to divide them in different plots. Than I would show percentage of each. Here a reproducible example test <- data.frame( test1 = sample(letters[1:2], 100, replace = TRUE), test2 = sample(letters[3:5], 100, replace = TRUE), test3 = sample(letters[9:11],100, replace = TRUE ) ) ggplot(test, aes(x=factor(test1))) + geom_bar(aes(fill=factor(test2), y=..prop.., group=factor

Barplot with ggplot 2 of two categorical variable facet_wrap according a third variable displayng percentage

醉酒当歌 提交于 2021-02-07 10:14:17
问题 I would like to barplot in ggplot2 a categorical variable grouped according a second categorical variable and use facet_wrap to divide them in different plots. Than I would show percentage of each. Here a reproducible example test <- data.frame( test1 = sample(letters[1:2], 100, replace = TRUE), test2 = sample(letters[3:5], 100, replace = TRUE), test3 = sample(letters[9:11],100, replace = TRUE ) ) ggplot(test, aes(x=factor(test1))) + geom_bar(aes(fill=factor(test2), y=..prop.., group=factor

How to have separate columns for duplicate x-axis values in geom_col()?

早过忘川 提交于 2021-01-29 19:54:11
问题 I have a dataframe as below (very simple structure) and I want to draw a column chart to show the amount for each date. The issue is that the date has duplicate entries (e.g., 2020-01-15 ). # A tibble: 5 x 2 date amount <date> <dbl> 1 2020-01-02 4000 2 2020-01-06 2568. 3 2020-01-15 2615. 4 2020-01-15 2565 5 2020-01-16 2640 When I try doing the following it somehow groups the similar dates together and draws a stacked column chart which is NOT what I want. df %>% ggplot(aes(x= factor(date), y