geom-bar

Adding group mean lines to geom_bar plot and including in legend

早过忘川 提交于 2019-12-18 06:59: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

How to make variable bar widths in ggplot2 not overlap or gap

守給你的承諾、 提交于 2019-12-17 22:51:06
问题 geom_bar seems to work best when it has fixed width bars - even the spaces between bars seem to be determined by width, according to the documentation. When you have variable widths, however, it does not respond as I would expect, leading to overlaps or gaps between the different bars (as shown here). To see what I mean, please try this very simple reproducible example: x <- c("a","b","c") w <- c(1.2, 1.3, 4) # variable widths y <- c(9, 10, 6) # variable heights ggplot() + geom_bar(aes(x = x,

Change bar plot colour in geom_bar with ggplot2 in r

余生颓废 提交于 2019-12-17 15:32:39
问题 I have the following in order to bar plot the data frame. c1 <- c(10, 20, 40) c2 <- c(3, 5, 7) c3 <- c(1, 1, 1) df <- data.frame(c1, c2, c3) ggplot(data=df, aes(x=c1+c2/2, y=c3)) + geom_bar(stat="identity", width=c2) + scale_fill_manual(values=c("#FF6666")) I end up having only grey bars: Grey bars for bar plot I would like to change the color of the bar. I already tried different scale_fill_manual from http://www.cookbook-r.com/Graphs/Colors_(ggplot2)/ but still have grey bars. Thank you for

Creating Stacked Bar Chart With one Variable for each Bar, using melt, and ggplot

大憨熊 提交于 2019-12-13 08:57:30
问题 This question is raising different points as the one I posted yesterday, with a better description, so I hope for your understanding. I have the following Data: Data <- data.frame(LMX = c(1.92, 2.33, 3.52, 5.34, 6.07, 4.23, 3.45, 5.64), Thriving = c(4.33, 6.54, 6.13, 4.85, 4.26, 6.32, 5.63, 4.55), Wellbeing = c(1.92, 2.33, 3.52, 2.34, 4.07, 3.23, 3.45, 4.64)) rownames(Data) <- 1:8 Now, my aim is to generate a flipped over bar chart that is showing one bar for each variable with all bars

Reordering columns by y-value in R?

我是研究僧i 提交于 2019-12-13 06:50:25
问题 I have a dataframe structured like this: > head(df) Zip Crimes Population CPC 1 78701 2103 6841 0.3074 2 78719 186 1764 0.1054 3 78702 1668 21334 0.0782 4 78723 2124 28330 0.0750 5 78753 3472 49301 0.0704 6 78741 2973 44935 0.0662 And I'm plotting it using this function: p = ggplot(df, aes(x=Zip, y=CPC)) + geom_col() + theme(axis.text.x = element_text(angle = 90)) And this is the graph I get: How can I order the plot by CPC, where the highest Zip codes are on the left? 回答1: Convert Zip to a

reordering bars in qplot

孤人 提交于 2019-12-13 01:26:30
问题 I have this data: > result_Q1_data HARM TYPE 834 96979 TORNADO 130 8428 EXCESSIVE HEAT 856 7461 TSTM WIND 170 7259 FLOOD 464 6046 LIGHTNING 275 3037 HEAT 153 2755 FLASH FLOOD 427 2064 ICE STORM 760 1621 THUNDERSTORM WIND 972 1527 WINTER STORM And I want to make a bar plot. I am using this command: qplot(TYPE,HARM,data=result_Q1_data,stat="identity",geom="bar", fill=EVTYPE) and get this plot How can I make the same plot where the data would decrease on the plot and there would not be words on

How to create custom color palette to be used by scale_fill_manual()

冷暖自知 提交于 2019-12-12 20:42:38
问题 Consider the following code that makes a bar chart with a purple color palette library(dplyr) library(ggplot2) dd <- mpg %>% group_by(manufacturer, cyl) %>% summarise(n = n()) %>% ungroup() mm <- dd %>% group_by(manufacturer) %>% summarise(mcyl = weighted.mean(cyl, n)) %>% arrange(mcyl) %>% ungroup() dd %>% left_join(mm) %>% ggplot(mapping = aes(x = reorder(manufacturer, mcyl), y = n, fill = factor(cyl))) + geom_bar(stat = "identity", position = "fill") + coord_flip() + scale_fill_brewer

Issue with “na” in arranging the bars in a bar plot in R and ggplot2

心不动则不痛 提交于 2019-12-12 06:38:33
问题 I am trying to create a Descending bars bar plot using ggplot2 and plotly in R. The data I am using is "a12" which is consumed by the ggplot under the line "#Final Data frame is consumed below". If you see the snap shot below, the "na" value in the column "a1" should come at second spot in the plot, however it does not follow the descending order and is pushed at the last. One way to cure this issue is to hardcode the value there, but I don't want to do that. Instead is there a way using

Rstudio reorder stacked ggplot geom_bar

十年热恋 提交于 2019-12-12 01:43:45
问题 So I've made a stacked Barplot with help of @Axeman . So far so good.. Now I would love to swap the Blue plot with the Red plot. I've literally tried everything using the order function in ggplot and I cant get it right. Here is the Plot: Stacked barplot Below, you can find an extract of the dataframe that was used for this plot (first row containts the header). Basically its a division name, followed by two types of savings (Repetitive and MDF) and the the last column contains the sum of

Loop functions with multiple variables for ggplot2

对着背影说爱祢 提交于 2019-12-11 17:57:05
问题 I want to build several plots from one large database, so that I have one plot for each Text (factor) and for each Measure (the many resulting measures of an eye tracking study). The following is a much simpler example of what I am trying to to: Let's say this is my dataset Text <- c(1,1,1,1,2,2,2,2,1,1,1,1,2,2,2,2) Position <- c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4) Modified <- c(1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0) Line_on_page <- c(1, 1, 1, 1, 2,2,2,2 ,1 ,1,1,1,2,2,2,2) IA_FIXATION_DURATION <- c