geom-bar

ggplot2 facet_grid with distinct x-axis labels using facet_grid

北城余情 提交于 2020-01-14 03:17:45
问题 I've been stuck on this issue for a long time. Basically I need to generate stacked bar plots of bacterial taxa in a 2 dimensional facet_grid. This is not a problem - however, I do need to use 2 different x-axis labels plots. I've looked at these threads which help, but still not satisfying: Force x-axis labels on facet_grid ggplot: drop lables Force x-axis labels on facet_grid ggplot: x-axis labels differ per row Force X axis text on for all facets of a facet_grid plot My first data frame:

ggplot2: Change color for each facet in bar chart

给你一囗甜甜゛ 提交于 2020-01-13 05:43:34
问题 I have a faceted bar chart done with ggplot2 with this code: ggplot(data_long, aes(x=region, y=wert)) + geom_bar(aes(fill = kat ), position = "dodge", width=.5, stat="identity") + labs(y = "Wähleranteil [ % ]", x = NULL, fill = NULL) + facet_grid(. ~ type) + theme_bw() + theme( strip.background = element_blank(), panel.grid.major = element_line(colour = "grey80"), panel.border = element_blank(), axis.ticks = element_blank(), panel.grid.minor.x=element_blank(), panel.grid.major.x=element_blank

ggplot2: Shift the baseline of barplot (geom_bar) to the minimum data value

无人久伴 提交于 2020-01-07 09:15:29
问题 I'm trying to generate a bar plot using geom_bar . My bars have both negative and positive values: set.seed(1) df <- data.frame(y=log(c(runif(6,0,1),runif(6,1,10))),se=runif(12,0.05,0.1),name=factor(rep(c("a","a","b","b","c","c"),2),levels=c("a","b","c")),side=factor(rep(1:2,6),levels=1:2),group=factor(c(rep("x",6),rep("y",6)),levels=c("x","y")),stringsAsFactors=F) This plot command plots the positive bars to face up and the negative ones to face down: library(ggplot2) dodge <- position_dodge

Reordering bars in ggplot2 bar graph using only one variable (w/o value or ranking)?

无人久伴 提交于 2020-01-06 06:03:52
问题 I'd like to ra-arrange the bars of my ggplot bar chart - and there is quite a number of similar entries here on stackoverflow (e.g. here). However, the question I have is: can you do this with only one variable (the one used for the bar graph) by telling ggplot not to sort alphabetically by labels but sort by take the count of identical labels as the value of interest. In my case, I have survey data on the question of which political party champions a certain issue/ is the most competent in a

using multiple variables in geom_bar with ggplot at same X (R)

喜你入骨 提交于 2020-01-05 08:42:43
问题 I'm trying to find how to do a barplot like this (barplot), but with my data (multiple variables). The data ( PlatformGlobe ) is the following: Platformvendor total_NA total_EU total_JP total_Other total_Global <chr> <dbl> <dbl> <dbl> <dbl> <dbl> microsoft 870.92 379.56 14.02 107.63 1372.92 nintendo 1743.71 774.77 758.91 189.71 3469.71 other 81.50 5.40 35.41 0.91 123.31 PC 93.34 140.37 0.17 21.88 256.56 sega 27.48 8.10 11.75 1.29 48.66 sony 1526.25 1092.01 470.47 461.29 3549.89 I would like

using multiple variables in geom_bar with ggplot at same X (R)

血红的双手。 提交于 2020-01-05 08:41:26
问题 I'm trying to find how to do a barplot like this (barplot), but with my data (multiple variables). The data ( PlatformGlobe ) is the following: Platformvendor total_NA total_EU total_JP total_Other total_Global <chr> <dbl> <dbl> <dbl> <dbl> <dbl> microsoft 870.92 379.56 14.02 107.63 1372.92 nintendo 1743.71 774.77 758.91 189.71 3469.71 other 81.50 5.40 35.41 0.91 123.31 PC 93.34 140.37 0.17 21.88 256.56 sega 27.48 8.10 11.75 1.29 48.66 sony 1526.25 1092.01 470.47 461.29 3549.89 I would like

Move axis labels in between plot and facet strip

梦想的初衷 提交于 2020-01-02 03:45:08
问题 I am trying to move the facet strip to the far left of my plot, so that the labels sit adjacent to the bars, and the grouping strips sit to their left (see my example below). I assume this must be done with Grobs, but I have little experience with that level of manipulation and would appreciate guidance. Data: structure(list(dept = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 5L, 5L, 5L, 5L, 5L, 5L,

Force bars to start from a lower value than 0 in ggplot geom_bar in R

北城余情 提交于 2019-12-30 11:31:46
问题 I want to plot bar plots using ggplot. I used scale_y_log10 to rescale the y axis. When use the script below, I get bars that are in both directions (upward and downward) and the bars start from 1. I understand that it is because, log10(1)=0. ggplot (data=dat, aes(x=Col2,y=Col4,fill=Col3,group=Col1))+ geom_bar(stat="identity")+ facet_grid(.~Col1,scales="free_x",space="fixed")+ ylab("")+xlab("")+scale_fill_discrete("")+ scale_y_log10("#Counts",breaks=c(.1,1,10,100,1000),expand=c(0,0))+ theme

Creating custom legend in bar chart with multiple color palettes

喜夏-厌秋 提交于 2019-12-25 08:47:49
问题 From this other Q&A, I have managed to create a bar chart with multiple color palettes Question : how to create a custom legend that prints the 3 color palettes as 4x3 matrix, with at least the row names (number of cylinders), like this: library(tidyr) purples %>% full_join(reds) %>% full_join(blues) %>% spread(manufacturer, colr) # A tibble: 4 x 4 cyl audi ford <NA> * <int> <chr> <chr> <chr> 1 4 #FEE5D9 #EFF3FF #F2F0F7 2 5 #FCAE91 #BDD7E7 #CBC9E2 3 6 #FB6A4A #6BAED6 #9E9AC8 4 8 #CB181D

Parse superscript in discrete axis values on geom_bar

依然范特西╮ 提交于 2019-12-24 18:49:29
问题 I'm trying to add a superscript to some x-axis values in order to connect to a footnote that'll be at the bottom of the page. The easy workaround would just be an asterisk instead of ^a but that won't work for my purposes. I did a lot of searching and while there's plenty of posts about superscripts in axis labels, I couldn't find any about superscripts in axis values. Most of them appeared to centera round adding a gg + labs(x = expression("blah^a")) . I did find this post about parsing