logo
down
shadow

Can I span groups of categories with horizontal lines in ggplot2


Can I span groups of categories with horizontal lines in ggplot2

Content Index :

Can I span groups of categories with horizontal lines in ggplot2
Tag : r , By : lewing
Date : November 26 2020, 04:01 AM

Hope that helps to a comment above by @camille, I learned about ggsignif, which is loaded by ggpubr. I added two ggsignif layers so I could set the line thickness (the size parameter) to zero for the two ungrouped sites.
library(dplyr)
library(ggplot2)
library(ggsignif)

reach <- c("Pool 4", "Pool 8", "Pool 16", "Pool 26", "LaGrange", "Open River")
n <- c(30, 6, 3, 29, 12, 76)
avg <- c(812, 819, 674, 649, 698, 679)
se <- c(24, 32, 43, 21, 31, 12)

dat <- data.frame(reach, n, avg, se)

dat <- dat %>% 
  mutate(reach = factor(reach, levels = reach, ordered = TRUE))

pos_nudge = 10
ggplot(dat, 
       aes(x = reach,
           y = avg)) +
  geom_point() +
  geom_linerange(aes(x = reach, 
                     ymin = avg - se, 
                     ymax = avg + se)) +
  geom_signif(y_position = max(avg + se + pos_nudge),
              xmin = c(1, 3),
              xmax = c(2, 4),
              annotation = c("A", "B"),
              tip_length = 0) +
  geom_signif(y_position = max(avg + se + pos_nudge),
              xmin = c(5, 6),
              xmax = c(5, 6),
              annotation = c("B", "B"),
              tip_length = 0,
              size = 0)

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Remove horizontal lines (ggplot2)


Tag : r , By : fstender
Date : March 29 2020, 07:55 AM
will help you You can find the solution how to hide the horizontal lines also in the Cookbook for R. Just look at the end of the Link i´ve posted in the thread.

ggplot2 draw dashed lines of same colour as solid lines belonging to different groups


Tag : r , By : Ivan Kitanovski
Date : March 29 2020, 07:55 AM
it should still fix some issue To add dotted lines you should add 2 geom_line() call where you provide y values inside aes(). There is no need to put data= and groups= arguments as they are the same as in ggplot() call. linetype="dotted" should be placed outside aes() call. For the colors you need only one scale_color_manual(). To remove dotted line pattern from legend you can override aesthetic using functions guides() and guide_legend().
ggplot(data, aes(x = x, y= mean, group = as.factor(data$group), 
                          colour=as.factor(data$group))) + 
  geom_line() + geom_point() + 
  geom_line(aes(y=lower),linetype="dotted") + 
  geom_line(aes(y=upper),linetype="dotted")+
  scale_color_manual(name="Groups",values=c("red", "blue"))+
  guides(colour = guide_legend(override.aes = list(linetype = 1)))

Horizontal barplot in ggplot2 with faces having different categories


Tag : r , By : Dominique Vocat
Date : March 29 2020, 07:55 AM
it should still fix some issue Ggplot2 does not currently support free scales with a non-cartesian coord or coord_flip.
So either you could plot them without flip:
ggplot(d,aes(y=qty,x=prd)) + 
facet_wrap(~cat, scale="free") +
geom_bar(stat="identity") +
theme_light()
d$n <- paste(d$cat, d$prd, sep="|")

ggplot(d,aes(y=qty,x=n)) + 
geom_bar(stat="identity") +
coord_flip() +
theme_light()

How to add horizontal lines showing means for all groups in ggplot2?


Tag : r , By : Reiner
Date : March 29 2020, 07:55 AM
With these it helps Is there a way to place horizontal lines with the group means on a plot without creating the summary data set ahead of time? I know this works, but I feel there must be a way to do this with just ggplot2. , Expanding on my comment:
ggplot(X, aes(x = x, y = y, color = grp)) +
  geom_point(shape = 19) +
  stat_smooth(method="lm", formula=y~1, se=FALSE)+
  theme_bw()
library(quantreg)
ggplot(X, aes(x = x, y = y, color = grp)) +
  geom_point(shape = 19) +
  stat_smooth(method="rq", formula=y~1, se=FALSE)+
  theme_bw()

ggplot2: how to sort the categories in horizontal bar charts?


Tag : r , By : Tonci Grgin
Date : March 29 2020, 07:55 AM
should help you out I removed some useless parts like the group, used 'modernized' geom_col(), but the trick was probably in doing sum per factor level instead of mean, which is the default for reorder. Consistently using the tidyverse functions usually saves you from unpleasant surprises, even if reorder would work here as well.
library(tidyverse)

dataframe %>%
  mutate(text = text %>% forcats::fct_reorder(count, sum)) %>%
  ggplot(aes(x = text, y = count, fill = count)) + 
  geom_col() +
  facet_wrap(~ group,  scales = "free_y") +
  coord_flip() 
Related Posts Related QUESTIONS :
  • Temporarily Disable Rprofile
  • Select certain region of column for lm
  • Convert multiple rows into one row depending on unique values in another column
  • Issues installing Plotly Dash for R
  • Is there an R function to retrieve values from a matrix of column names?
  • R;Too slow to overate loops for million vectors
  • How to optimize intersect of rows and columns in a matrix?
  • Format and export the output of Mann-Kendall test in R to excel from Rstudio
  • how to calculate cumsum with depreciation in a grouped dataframe?
  • reshape wide to long based on part of column name
  • How to get a hyperlink for the words in a description in an r dataframe?
  • shinymeta works locally but breaks when published to shinyapps.io
  • Deparse and (un)escape quotes
  • Regression table with clustered standard errors in R jupyter notebook?
  • Disaggregate quarterly data to daily data in R keeping values?
  • How to save output to console and file simultaneously in RStudio server?
  • Why does data.table j have a different environment when directly calling mget() vs calling mget() inside another functio
  • scale_fill_viridis_c color bar on a log scale
  • How to change the lab name corresponding to function in ggplot
  • R, filtering for an element in a list in a dataframe cell
  • Extracting only bottom temperature from 4d NetCDF file
  • How to add/wrap lines of text to .tex with .sh script
  • R - building new variables from sequenced data
  • Sum rows values one after the other
  • Nesting ifelse inside summarytools
  • How best to divide different levels of a factor by one another in dataframe in R?
  • Why does my code run multiple times before I type data into the table? How do I make an action button that creates a tab
  • How to impute missing values not at random?
  • Set the y limits of an added average line of a plotly plot
  • how to calculate a new column after grouping with dplyr
  • Extract data from rows creating new columns using R
  • Create a filled area line plot with plotly
  • When do I need parentheses around an if statement to control the sequence of a formula in R?
  • my graph in ggplot2 contains an "e" character in y-axis
  • Making variables immutable in R
  • R: Difference between the subsequent ranks of a item group by date
  • Match data within multiple time-frames with dplyr
  • Conditional manipulation and extension of rows in data.table also considering previous extensions without for-loop
  • Conditional formula referring to preview row in DF not working
  • Set hoverinfo text in plotly scatterplot
  • Histogram of Sums from Categorical/Binary Data
  • Efficiently find set differences and generate random sample
  • Find closest points from data set B to point in data set A, using lat long in R
  • dplyr join on column A OR column B
  • Replace all string if row starts with (within a column)
  • Is there a possibility to combine position_stack and nudge_x in a stacked bar chart in ggplot2?
  • How can I extract bounding boxes in a row-wise manner using R?
  • How do I easily sum up values in different columns?
  • Reading numeric Date value from CSV file to data.frame in "R"
  • R programming: creating a stacked bar graph, with variable colors for each stacked bar
  • How to identify all columns that contain binary representation
  • Filter different groups by different factor levels
  • Saving .xlsx file to disc, form http post request
  • Add an "all" option under the filter that selects the number of rows displayed in a datatable
  • How to select second column of every xts in list
  • Generate a frequency dataframe out of an input dataframe
  • Why manual autocorrelation does not match acf() results?
  • Merge 3 dataframes which are different to each other
  • remove adjacent duplicates from string
  • How to change the position of stacked stacked bar chart in ggplot in R?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com