geom-bar

add geom_bar to circular plot ggplot2

耗尽温柔 提交于 2019-12-24 02:35:07
问题 I have a data frame that looks like so: dat<-structure(list(x = 1:14, y = c(1.26071476002898, 1.97600316441492, 2.41629009067185, 3.48953782319898, 10, 8.49584395945854, 3.80688560348562, 3.07092373734549, 2.96665740569527, 2.73020216450355, 2.39926441554745, 2.4236111796397, 2.63338121290737, 2.13662243060685)), .Names = c("x", "y"), row.names = c(NA, -14L), class = "data.frame") x y 1 1.260715 2 1.976003 3 2.416290 4 3.489538 5 10.000000 6 8.495844 7 3.806886 8 3.070924 9 2.966657 10 2

Maintain order of geom_bar() fill with ggplot2

拜拜、爱过 提交于 2019-12-24 01:23:55
问题 I have a sediment core dataset that I would like to portray graphically with geom_bar() in ggplot2 and fill with a variable. The fill variable alternates with every other level of fill, but with the new version (2.2.1) of ggplot2 I cannot maintain this fill pattern. This is discussed here but I cannot find a workable solution. library(ggplot2) site<-c(rep('a',14),rep('z',8)) sedcore<-1 fill<-c("y","n","y","n","y","n","y","n","y","n","y","n","y","n","y","n","y","n","y","n","y","n") df <- data

ggplot2: geom_bar with custom y limits

杀马特。学长 韩版系。学妹 提交于 2019-12-24 00:47:17
问题 I want to draw a bar chart with ggplot2 along with custom y limits. Type <- LETTERS[1:5] Y <- c(99, 99.5, 99.0, 98.8, 98.5) df <- data.frame(Type, Y) The following code works fine for bar chart: library(ggplot2) ggplot(data = df, mapping = aes(x = Type, y = Y, fill = Type)) + geom_bar(stat = "identity") + theme_bw() However, I'm not able to set the y limits. See the code below. ggplot(data = df, mapping = aes(x = Type, y = Y, fill = Type)) + geom_bar(stat = "identity") + scale_y_continuous

ggplot2: Add label on barplot if position = “fill”

穿精又带淫゛_ 提交于 2019-12-22 16:02:01
问题 I would like to add %-figures on a filled barplot. Here is the plot with the labels at the wrong places: Here is the dataframe: x0 <- expand.grid(grp = c("G1","G2") , treat = c("T1","T2") , out = c("out1","out2","out3","out4") ) set.seed(1234) x0$n <- round(runif(16,0,1)*100,0) head(x0) grp treat out n 1 G1 T1 out1 11 2 G2 T1 out1 62 3 G1 T2 out1 61 4 G2 T2 out1 62 5 G1 T1 out2 86 6 G2 T1 out2 64 Now, I add the sum within grp/treat to the dataframe (using sql, sorry!): x0 <- sqldf(paste(

ggplot2: Add label on barplot if position = “fill”

自作多情 提交于 2019-12-22 16:02:00
问题 I would like to add %-figures on a filled barplot. Here is the plot with the labels at the wrong places: Here is the dataframe: x0 <- expand.grid(grp = c("G1","G2") , treat = c("T1","T2") , out = c("out1","out2","out3","out4") ) set.seed(1234) x0$n <- round(runif(16,0,1)*100,0) head(x0) grp treat out n 1 G1 T1 out1 11 2 G2 T1 out1 62 3 G1 T2 out1 61 4 G2 T2 out1 62 5 G1 T1 out2 86 6 G2 T1 out2 64 Now, I add the sum within grp/treat to the dataframe (using sql, sorry!): x0 <- sqldf(paste(

How expand ggplot bar scale on one side but not the other without manual limits

半城伤御伤魂 提交于 2019-12-22 05:09:00
问题 The goal is to get rid of the space between the tick marks and the base of the bars without cutting off any of the percentage labels beyond the other end of the bars. I am running dozens of bar graphs using R's ggplot2 and trying to follow our organizational style guide, which was developed using Excel manually for each graph. The maximum length bars are of different lengths in the different graphs and could change as the source data changes, so I don't want to manually set limits. [Perhaps

Constant width in ggplot barplots

☆樱花仙子☆ 提交于 2019-12-21 12:14:48
问题 How to make the width of bars and spaces between them fixed for several barplots using ggplot , having different number of bars on each plot? Here is a failed try: m <- data.frame(x=1:10,y=runif(10)) ggplot(m, aes(x,y)) + geom_bar(stat="identity") ggplot(m[1:3,], aes(x,y)) + geom_bar(stat="identity") Adding width=1 to geom_bar(...) doesn't help as well. I need the second plot automatically to have less width and the same bar width and spaces as the first one. 回答1: Edit: It appears the OP

R - ggplot - Rounded extremity for geom_bar

好久不见. 提交于 2019-12-19 03:16:18
问题 This is a simple example of what my barplot look like : x <- data.frame(aa=c(0.2,0.6,0.1), dd = c(1,2,3)) x <- melt(x, "dd") y <- data.frame(bb=c(0.4,0.5), dd = c(1,2)) y <- melt(y, "dd") z <- data.frame(cc=c(0.5,0.25,0.1,0.05), dd = c(1,2,3,4)) z <- melt(z, "dd") x=rbind(x,y,z) col=c("white","grey","blue","white","red","white","green","blue","green") ggplot(x, aes(x = variable, y = value)) + geom_bar(stat = "identity", fill = col) I'm wondering if there is a way to have rounded ends for my

R - ggplot - Rounded extremity for geom_bar

落爺英雄遲暮 提交于 2019-12-19 03:16:11
问题 This is a simple example of what my barplot look like : x <- data.frame(aa=c(0.2,0.6,0.1), dd = c(1,2,3)) x <- melt(x, "dd") y <- data.frame(bb=c(0.4,0.5), dd = c(1,2)) y <- melt(y, "dd") z <- data.frame(cc=c(0.5,0.25,0.1,0.05), dd = c(1,2,3,4)) z <- melt(z, "dd") x=rbind(x,y,z) col=c("white","grey","blue","white","red","white","green","blue","green") ggplot(x, aes(x = variable, y = value)) + geom_bar(stat = "identity", fill = col) I'm wondering if there is a way to have rounded ends for my

ggplot2: geom_text resize with the plot and force/fit text within geom_bar

邮差的信 提交于 2019-12-18 12:24:20
问题 This is actually two questions in one (not sure if goes against SO rules, but anyway). First question is how can I force a geom_text to fit within a geom_bar ? (dynamically according to the values plotted) Looking around, the solutions I found were changing the size of the label. That certainly works, but not for every case. You can change the size for a specific plot to make the text fit within the bar, but when the data changes, you may need to manually change the size of the text again. My