Questions tagged [ggnewscale]

Use this tag for questions related to the ggnewscale package. The ggnewscale package provides functions to "... make it painless to use multiple colour and fill scales in ggplot2."

The package provides functions to make it

... painless to use multiple colour and fill scales in .

For an overview over the package and the function reference see the package site.

14 questions
5
votes
1 answer

Split legend into two or multiple columns in a plot using ggnewscale::new_scale() with ggplot2 in R

after following Stefan's very helpful answer to this post, where he uses ggnewscale::new_scale(), I now am stuck with the following question: "How to arrange the custom legends from ggnewscale into multiple vertical columns?" like it is usually done…
David
  • 51
  • 5
3
votes
1 answer

How to change legend title position when I have multiple scales created with ggnewscale package?

I created a plot which has 2 color scales and 2 linetype scales made with the ggnewscale package. I want the legend to appear at the bottom of the plot and the legend titles to appear above the labels. I did it halfway, because in my attempts, the…
Daniel Valencia C.
  • 2,159
  • 2
  • 19
  • 38
2
votes
2 answers

Adding background transparency and custom ordering in legend in ggplot

Let say I have below ggplot library(ggplot2) library(ggnewscale) data = structure(list(grp1 = c("X", "X", "X", "X", "Y", "Y", "Y", "Y" ), grp2 = c("A", "B", "C", "D", "A", "B", "C", "D"), val = c(1, 2, 3, 4, 3, 4, 5, 6)), row.names = c(NA, -8L),…
Bogaso
  • 2,838
  • 3
  • 24
  • 54
2
votes
1 answer

How to fix the legend order in ggnewscale

The plot Im generating using this code gives me this plot The issue is I can't able to match the order that is present in the plot My code p <- df %>% ggplot(aes(name, perc)) + geom_col(data = ~ filter(.x, name == "FAB") %>% rename(FAB = value),…
PesKchan
  • 868
  • 6
  • 14
2
votes
1 answer

Plotting continuous distribution in horizontal bar plot

This was my earlier question where it was solved using multiple distribution. I want to plot the continuous variable like age or tumor mutation burden as shown in first figure with a range like a window such 20-30 age group or some mutational burden…
PesKchan
  • 868
  • 6
  • 14
2
votes
1 answer

Align legend horizontal ggplot2

I am curious as to whether there is a way to stack legends horizontally rather than vertically in ggplot2 and ggnewscale: Example using mtcars dataset: ggplot(mtcars, aes(x = mpg, y = cyl)) + geom_point(aes(col = gear)) + …
2
votes
1 answer

ggplot melted data sharing common aesthetics

I need to plot a graph from a melted data.table that mixes three geoms: geom_line, geom_col and geom_point. geom_line and geom_point share a the color aesthetics: set.seed(1) time <- 1:10 mag <- 10:20 q_mag <- c("up", "up", "down") l_a <-…
Fabio Correa
  • 1,257
  • 1
  • 11
  • 17
2
votes
1 answer

Stacked bar plot with multiple or different legend for each group

Is it possible to generate a barplot like in the following link using ggplot? https://photos.app.goo.gl/E3MC461dKaTZfHza9 here is what I did library(ggplot2) df <-…
Aimin Yan
  • 23
  • 5
1
vote
2 answers

Grouping legend of ggplot for stacked bar chart

Let say I have below ggplot to draw a stacked bar chart library(ggplot2) col_define = c('red', 'orange', 'blue', 'lightblue') names(col_define) = c('A', 'B', 'C', 'D') data = rbind(data.frame('grp1' = 'X', 'grp2' = c('A', 'B', 'C', 'D'), 'val' =…
Bogaso
  • 2,838
  • 3
  • 24
  • 54
1
vote
1 answer

Is there a way to detect if a scale_linetype_manual has been added to a ggplot?

I need to be able to detect whether a ggplot passed into a function already has a scale_linetype_manual added to it so that I know whether to use ggnewscale and add another new_scale("linetype") to it.
1
vote
1 answer

How to fix legend order using ggplot in R?

I am creating a plot that has 2 legends using both ggplot2 and ggnewscale. What I'm trying to achieve is to fix the order of the separate legends so they always appear in the same order. The images and code below show a basic example of the issue…
Electrino
  • 2,636
  • 3
  • 18
  • 40
0
votes
0 answers

ggplot2: grouping legend items by a variable for combined geom_path and geom_point

I have a connected scatterplot using geom_path and geom_point. I currently have the lines connecting the points by a grouping variable (Species_ordered) and each level of that variable symbolized by a different shape. I have another grouping…
jguevara
  • 1
  • 2
0
votes
1 answer

How to fix y axis order in ggnescale

I'm building a heatmap using different data frame and I'm using ggnewscale to have different color gradients. The problem is that when I use new_scale("fill") I lost control on the y axis order. Do you know how to fix it? This is an…
Erik
  • 39
  • 3
0
votes
1 answer

Add Both Legends to a Plot

I have a plot that I have made counting the number of genes over a period of time in two samples. I would like to plot both sets of numbers in a waterfall chart. I am able to get the chart but I have difficulty getting both legends to show up. I…