facet

Add text on top of a facet dodged barplot using ggplot2

别来无恙 提交于 2019-11-26 14:38:19
问题 I'd like to plot a dodged barplot for two different years and put the revenue numbers on top of the bar accordingly. After trying quite some suggestion I found over here, I still can't quite get what I want (all the numbers were displayed in the middle of the middle bars/columns instead of spreading equally). Any suggestion would be appreciated. Thanks! My latest attempt # Disable scientific notation options("scipen" = 100, "digits" = 1) censusData <- structure(list(Year = c(2012L, 2007L,

ggplot, facet, piechart: placing text in the middle of pie chart slices

浪子不回头ぞ 提交于 2019-11-26 11:21:35
I'm trying to produce a facetted pie-chart with ggplot and facing problems with placing text in the middle of each slice: dat = read.table(text = "Channel Volume Cnt AGENT high 8344 AGENT medium 5448 AGENT low 23823 KIOSK high 19275 KIOSK medium 13554 KIOSK low 38293", header=TRUE) vis = ggplot(data=dat, aes(x=factor(1), y=Cnt, fill=Volume)) + geom_bar(stat="identity", position="fill") + coord_polar(theta="y") + facet_grid(Channel~.) + geom_text(aes(x=factor(1), y=Cnt, label=Cnt, ymax=Cnt), position=position_fill(width=1)) The output: What parameters of geom_text should be adjusted in order to

R + ggplot2 => add labels on facet pie chart [duplicate]

你说的曾经没有我的故事 提交于 2019-11-26 11:09:24
问题 This question already has answers here : ggplot, facet, piechart: placing text in the middle of pie chart slices (4 answers) Closed 4 years ago . I want to add data labels on faceted pie char. Maybe someone can can help me. My data: year <- c(1,2,1,2,1,2) prod <- c(1,1,2,2,3,3) quantity <- c(33,50,33,25,34,25) df <- data.frame(year, prod, quantity) rm(year, prod, quantity) Code: library(ggplot2) # center\'s calculated by hand centr2 <- c(16, 25, 49, 62.5, 81, 87.5) ggplot(data=df, aes(x

different size facets proportional of x axis on ggplot 2 r

人走茶凉 提交于 2019-11-26 09:44:06
问题 The following is a situation: group1 <- seq(1, 10, 2) group2 <- seq(1, 20, 3) x = c(group1, group2) mydf <- data.frame (X =x , Y = rnorm (length (x),5,1), groups = c(rep(1, length (group1)), rep(2, length(group2)))) ggplot(mydf, aes(X, Y, group= groups)) + geom_point()+ facet_grid (.~ group) Different facets are scaled by x limits in the following plot: ggplot(mydf, aes(X, Y, group= groups)) + geom_point()+ facet_grid (.~ group, scales = \"free_x\") As total width of x has meaning, I want to

Nested facets in ggplot2 spanning groups

痴心易碎 提交于 2019-11-26 08:16:43
问题 I encountered a situation in which I want to create a plot that was facetted by three grouping variables. To do so, I would simply use facet_grid(f1 ~ f2 + f3) , but the issue here is that the labels for f2 would be redundant, and it would be much better to have them span the facets for f3 nested within f2. MWE: library(\'tibble\') library(\'ggplot2\') df <- tribble( ~x, ~y, ~f1, ~f2, ~f3, 0.5, 0.5, \"a\", \"a\", \"a\", 0.5, 0.5, \"b\", \"a\", \"a\", 0.5, 0.5, \"a\", \"b\", \"a\", 0.5, 0.5, \

How to add different lines for facets

偶尔善良 提交于 2019-11-26 08:10:32
问题 I have data where I look at the difference in growth between a monoculture and a mixed culture for two different species. Additionally, I made a graph to make my data clear. I want a barplot with error bars, the whole dataset is of course bigger, but for this graph this is the data.frame with the means for the barplot. plant species means Mixed culture Elytrigia 0.886625 Monoculture Elytrigia 1.022667 Monoculture Festuca 0.314375 Mixed culture Festuca 0.078125 With this data I made a graph in

Place a legend for each facet_wrap grid in ggplot2

纵然是瞬间 提交于 2019-11-26 07:31:37
问题 I have this data frame: Date Server FileSystem PercentUsed 1 12/1/2011 A / 60 2 1/2/2012 A /var 50 3 2/1/2012 A tmp 90 4 2/10/2012 A /db 86 5 2/13/2012 A /app 90 6 12/1/2011 B C: 67 7 1/2/2012 B D: 67 8 2/1/2012 B F: 34 9 2/10/2012 B /restore 89 10 2/13/2012 B G: 56 11 12/1/2011 C / 90 12 1/2/2012 C /tmp 78 13 2/1/2012 C /data 67 14 2/10/2012 C /Storage 34 15 2/13/2012 C /database 12 dput(x) structure(list(Date = structure(c(2L, 1L, 3L, 4L, 5L, 2L, 1L, 3L, 4L, 5L, 2L, 1L, 3L, 4L, 5L), .Label

How do you add a general label to facets in ggplot2?

大城市里の小女人 提交于 2019-11-26 06:59:43
问题 I often have numeric values for faceting. I wish to provide sufficient information to interpret these faceting values in a supplemental title, similar to the axis titles. The labeller options repeat much unnecessary text and are unusable for longer variable titles. Any suggestions? The default: test<-data.frame(x=1:20, y=21:40, facet.a=rep(c(1,2),10), facet.b=rep(c(1,2), each=20)) qplot(data=test, x=x, y=y, facets=facet.b~facet.a) What I would love: The best I can do in ggplot: qplot(data

Setting individual axis limits with facet_wrap and scales = “free” in ggplot2

女生的网名这么多〃 提交于 2019-11-26 06:54:25
I'm creating a facetted plot to view predicted vs. actual values side by side with a plot of predicted value vs. residuals. I'll be using shiny to help explore the results of modeling efforts using different training parameters. I train the model with 85% of the data, test on the remaining 15%, and repeat this 5 times, collecting actual/predicted values each time. After calculating the residuals, my data.frame looks like this: head(results) act pred resid 2 52.81000 52.86750 -0.05750133 3 44.46000 42.76825 1.69175252 4 54.58667 49.00482 5.58184181 5 36.23333 35.52386 0.70947731 6 53.22667 48

Fixing the order of facets in ggplot

折月煮酒 提交于 2019-11-26 05:55:50
问题 Data: type size amount T 50% 48.4 F 50% 48.1 P 50% 46.8 T 100% 25.9 F 100% 26.0 P 100% 24.9 T 150% 21.1 F 150% 21.4 P 150% 20.1 T 200% 20.8 F 200% 21.5 P 200% 16.5 I need to plot a bargraph of the above data using ggplot (x-axis -> \"type\", y-axis -> \"amount\", group by \"size\"). When I used the following code, I am not getting the variable \"type\" and as well as \"size\" in the order shown in the data. Please see the figure. I have used the following code for that. ggplot(temp, aes(type,