facet

facet_wrap add geom_hline

北城以北 提交于 2019-11-27 16:06:12
I have the following code for my ggplot - the facet_wrap function draws out 20 plots on the page for each Name and there are 5 Pcode along the x-axis. I would like to calculate the average TE.Contr for each Name and plot that value as a horizontal line on each of the plots (which are split out by Facet_wrap). Currently my codes plots the average of ALL TE.Contr. values instead of the average TE.Contr. of the specific Name. T<-ggplot(data = UKWinners, aes(x = Pcode, y = TE.Contr., color = Manager)) + geom_point(size =3.5)+ geom_hline(aes(yintercept = mean(TE.Contr.))) T<-T + facet_wrap(~ Name,

how to change strip.text labels in ggplot with facet and margin=TRUE

白昼怎懂夜的黑 提交于 2019-11-27 14:13:22
问题 I have looked here but still can't figure it out. How do I change the strip.text.x labels in a ggplot with faceting? Specifically I am using facet_grid with margins. The strip.text label for the margin is "(all)" - but since I am in a non-english speaking country I would rather write "Total" or something similar in my native tongue. opts(stip.text.x=c(levels(facetvariabel,"Total")) does not work. Any ideas? Example (not really the best dataset for this - but I guess it will work) ggplot(cars,

can I change the position of the strip label in ggplot from the top to the bottom?

荒凉一梦 提交于 2019-11-27 12:38:57
问题 I know this is not quite a data visualization issue, but the boss asked for it, so I need to figure out if it is possible. Thanks! 回答1: An answer for those searching in 2016. As of ggplot2 2.0, the switch argument will do this for facet_grid or facet_wrap : By default, the labels are displayed on the top and right of the plot. If "x", the top labels will be displayed to the bottom. If "y", the right-hand side labels will be displayed to the left. Can also be set to "both". ggplot(...) + ... +

Add text on top of a facet dodged barplot using ggplot2

你。 提交于 2019-11-27 09:18:49
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, 2012L, 2007L, 2012L, 2007L, 2012L, 2007L, 2012L, 2007L, 2012L, 2007L, 2012L, 2007L, 2012L, 2007L, 2012L,

How do I place an identical smooth on each facet of a ggplot2 object?

感情迁移 提交于 2019-11-27 07:59:30
问题 Here's an example: eg <- data.frame(x = c(1:50, 50:1), y = c(1:50, 1:50) + rnorm(100), g = rep(c("a","b"), each=50)) qplot(x, y, data = eg) + facet_wrap(~ g) + geom_smooth() I'd like to be able to plot the overall smooth on both facets as well as having the facet-specific smooths. Edit: here's one way. my.smooth <- gam(y ~ s(x), data = eg) my.data <- data.frame(x = 1:50) my.data$y <- predict(my.smooth, newdata = my.data) qplot(x, y, data = eg) + facet_wrap(~ g) + geom_smooth() + geom_smooth

ggplot2: More complex faceting

牧云@^-^@ 提交于 2019-11-27 06:08:21
问题 I have a heatmap that continues to become more and more complex. An example of the melted data: head(df2) Class Subclass Family variable value 1 A chemosensory family_1005117 caenorhabditis_elegans 10 2 A chemosensory family_1011230 caenorhabditis_elegans 4 3 A chemosensory family_1022539 caenorhabditis_elegans 10 4 A other family_1025293 caenorhabditis_elegans NA 5 A chemosensory family_1031345 caenorhabditis_elegans 10 6 A chemosensory family_1033309 caenorhabditis_elegans 10 tail(df2)

Add x and y axis to all facet_wrap

青春壹個敷衍的年華 提交于 2019-11-27 05:32:43
问题 It is often desirable to minimize ink in a plot. I have a faceted plot ( facet_wrap ) and would like to remove as much ink as possible yet maintain readability. I have set it up as I'd like except the x and y axis is not present for the facets (subplots) unless on the far left or bottom. With so much ink removed I believe the eye needs these cues and am asking how to put the x and y axis in all plots within a facet_wrap . Below is my code thus far, the current output and the deired output

Missing data when Supplying a Dual-axis--Multiple-traces to subplot

陌路散爱 提交于 2019-11-27 04:49:22
问题 Data is provided at the bottom of the question. I am trying to use subplot with plotly objects which one of them has multiple series in it. When I use subplot one of the series in the first graph does not show up in the final product. Look at the code below: library(plotly) library(dplyr) sec_y <- list(tickfont = list(color = "red"), overlaying = "y", side = "right", title = "Lft") pp1 <- fmean1 %>% group_by(grp) %>% plot_ly() %>% add_lines(x = ~hour, y = ~fmgd, name = "FMGD", colour = "blue"

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

余生颓废 提交于 2019-11-27 04:23:39
This question already has an answer here: ggplot, facet, piechart: placing text in the middle of pie chart slices 4 answers 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=factor(1), y=quantity, fill=factor(prod))) + geom_bar(stat="identity") + geom_text(aes(x= factor(1), y=centr2, label = df$quantity)

Nested facets in ggplot2 spanning groups

荒凉一梦 提交于 2019-11-27 04:16:38
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, "b", "b", "a", 0.5, 0.5, "a", "a", "b", 0.5, 0.5, "b", "a", "b", 0.5, 0.5, "a", "b", "b", 0.5, 0.5, "b", "b", "b" ) p <-