geom-bar

Bars in geom_bar are not of equal width

断了今生、忘了曾经 提交于 2019-12-02 10:52:57
问题 For the following data frame I want to make several bar plots using ggplot . df <- data.frame(Disease = c("Disease1","Disease2","Disease3","Disease3","Disease3","Disease4","Disease5","Disease5","Disease6","Disease4","Disease2","Disease2","Disease1","Disease7","Disease1","Disease1","Disease7","Disease6","Disease3","Disease6"), Week = c(3,52,46,47,19,39,42,46,44,45,46,42,45,48,44,44,43,42,45,47), Year = c(2015,2015,2015,2016,2015,2015,2016,2016,2015,2015,2015,2015,2016,2016,2016,2015,2016,2016

Bars in geom_bar are not of equal width

孤者浪人 提交于 2019-12-02 07:18:23
For the following data frame I want to make several bar plots using ggplot . df <- data.frame(Disease = c("Disease1","Disease2","Disease3","Disease3","Disease3","Disease4","Disease5","Disease5","Disease6","Disease4","Disease2","Disease2","Disease1","Disease7","Disease1","Disease1","Disease7","Disease6","Disease3","Disease6"), Week = c(3,52,46,47,19,39,42,46,44,45,46,42,45,48,44,44,43,42,45,47), Year = c(2015,2015,2015,2016,2015,2015,2016,2016,2015,2015,2015,2015,2016,2016,2016,2015,2016,2016,2016,2015), Number = c(1,1,6,5,1,1,4,12,4,15,6,15,6,11,4,2,9,1,4,1)) I use the following syntax which

In ggplot2, can borders of bars be changed on only one side? (color, thickness)

被刻印的时光 ゝ 提交于 2019-12-01 20:42:00
I know, 3D Barcharts are a sin. But i´m asked to do them and as a trade-off i suggested to only make a border with a slightly darker color than the bar´s on the top and the right side of the bar. Like that, the bars would have some kind of "shadow" (urgh) but at least you still would be able to compare them. Is there any way to do this? ggplot(diamonds, aes(clarity)) + geom_bar() Another possibility, using two sets of geom_bar . The first set, the green ones, are made slightly higher and offset to the right. I borrow the data from @Didzis Elferts. ggplot(data = df2) + geom_bar(aes(x = as

Reduce space between groups of bars in ggplot2

眉间皱痕 提交于 2019-12-01 17:49:40
问题 I haven't been able to remove extra white space flanking groups of bars in geom_plot. I'd like to do what Roland achieves here: Remove space between bars ggplot2 but when I try to implement his solution I get the error "Warning message: geom_bar() no longer has a binwidth parameter. Please use geom_histogram() instead." I added this line of code to my plot (trying different widths): geom_histogram(binwidth = 0.5) + which returns "Error: stat_bin() must not be used with a y aesthetic." and no

Reduce space between groups of bars in ggplot2

拥有回忆 提交于 2019-12-01 17:44:44
I haven't been able to remove extra white space flanking groups of bars in geom_plot. I'd like to do what Roland achieves here: Remove space between bars ggplot2 but when I try to implement his solution I get the error "Warning message: geom_bar() no longer has a binwidth parameter. Please use geom_histogram() instead." I added this line of code to my plot (trying different widths): geom_histogram(binwidth = 0.5) + which returns "Error: stat_bin() must not be used with a y aesthetic." and no plot. Data: mydf<- data.frame(Treatment = c("Con", "Con", "Ex", "Ex"), Response = rep(c("Alive", "Dead"

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

£可爱£侵袭症+ 提交于 2019-11-30 06:46:27
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 real-life problem is that I need to generate the same plot for constantly changing data (daily), so I

ggplot geom_bar: meaning of aes(group = 1)

ぃ、小莉子 提交于 2019-11-29 22:21:32
I am learning geom_bar on section 3.7 of r4ds.had.co.nz. I run a code like this: library(ggplot2) ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut, y = ..prop.., group = 1)) Then I have this plot: The point is, if I exclude the "group = 1" part: library(ggplot2) ggplot(data = diamonds) + geom_bar(mapping = aes(x = cut, y = ..prop..)) The plot will be wrong, But if I replace group = 1 by group = 2 or group = "x", the plot still looks correct. So I don't quite understand the meaning of group = 1 here and how to use it. group="whatever" is a "dummy" grouping to override the default

How to add custom labels from a dataset on top of bars using ggplot/geom_bar in R?

為{幸葍}努か 提交于 2019-11-29 11:42:09
I have the attached datasets and use this R code to plot the data: plotData <- read.csv("plotdata.csv") ix <- 1:nrow(plotData) long <- melt(transform(plotData, id = ix), id = "id") # add id col; melt to long form ggp2 <- ggplot(long, aes(id, value, fill = variable))+geom_bar(stat = "identity", position = "dodge")+ scale_x_continuous(breaks = ix) + labs(y='Throughput (Mbps)',x='Nodes') + scale_fill_discrete(name="Legend", labels=c("Inside Firewall (Dest)", "Inside Firewall (Source)", "Outside Firewall (Dest)", "Outside Firewall (Source)")) + theme(legend.position="right") + # The position of

geom_bar + geom_line: with different y-axis scale?

懵懂的女人 提交于 2019-11-29 11:31:52
Is there any way to plot geom_bar with geom_line like the following chart. I have come up with the two separate charts. How to combine them with two different axes on the left and right sides respectively. library(ggplot2) temp = data.frame(Product=as.factor(c("A","B","C")), N = c(17100,17533,6756), n = c(5,13,11), rate = c(0.0003,0.0007,0.0016), labels = c(".03%",".07%",".16%")) p1 = ggplot(data = temp, aes(x=Product,y=N))+ geom_bar(stat="identity",fill="#F8766D")+geom_text(aes(label=n,col="red",vjust=-0.5))+ theme(legend.position="none",axis.title.y=element_blank(),axis.text.x = element_text

Adding group mean lines to geom_bar plot and including in legend

人盡茶涼 提交于 2019-11-29 11:25:09
I want to be able to create a bar graph which shows also shows the mean value for bars in each group. AND shows the mean bar in the legend. I have been able to get this graph Bar chart with means using the code below, which is fine, but I would like to be able to see the mean lines in the legend. ##The data to be graphed is the proportion of persons receiving a treatment ## (num=numerator) in each population (denom=demoninator). The population is ##grouped by two age groups and (Age) and further divided by a categorical ##variable V1 ###SET UP DATAFRAME### require(ggplot2) df <- data.frame(V1