logo
down
shadow

Adding an extra item to the legend


Adding an extra item to the legend

By : Syed Zain Shah hamda
Date : November 24 2020, 03:01 PM
fixed the issue. Will look into that further Add dummy aes() to geom_point - for example fill that is named significant aes(fill = "Significant").
code :
# Using OPs data
library(ggplot2)
ggplot(GEE, aes(y=beta, x=reorder(trait, beta), group=analysis)) + 
  geom_point(data = GEE[GEE$signif == 1, ],
             color="red",
             shape = "*", 
             size=12,
             aes(fill = "Significant")) +
  geom_point(aes(color=analysis)) +
  geom_errorbar(aes(ymin=beta-2*se, ymax=beta+2*se,color=analysis), width=.2,
                position=position_dodge(.2)) +
  geom_hline(yintercept = 0) +
  theme_light() +
  theme(axis.title.y=element_blank(),
        legend.title=element_blank()) +
  coord_flip() +
  guides(colour = guide_legend(order = 1), 
         fill = guide_legend(override.aes = list(size = 5))) +
  theme(legend.margin = margin(-0.5,0,0,0, unit="cm"))


Share : facebook icon twitter icon
How to remove extra legend after adding statistics to stacked barplot?

How to remove extra legend after adding statistics to stacked barplot?


By : steni
Date : March 29 2020, 07:55 AM
will be helpful for those in need That spurious legend appears because you're putting all sort of stuff inside aes that don't need to be there. Try this:
code :
ggplot(data=to_graph, aes(x=BAM, y=Reads, fill=Mapping)) +
     geom_bar(stat="identity",position = "stack") + 
    geom_text(aes(label=paste(round(fraction*100),"%", sep="")),size = 3,vjust=0,position="stack")
Adding legend item for vertical line (mean) to already existing legend

Adding legend item for vertical line (mean) to already existing legend


By : Vineet Patnaik
Date : March 29 2020, 07:55 AM
wish helps you I think you will be able to get the result you are looking for by adjusting the legend.box
code :
library(ggplot2)
data('diamonds')

plot_data <- subset(diamonds, cut %in% c("Ideal", "Premium"))
means     <- aggregate( price ~ cut, plot_data, mean)

ggplot(plot_data, aes(x = price, fill = cut)) + 
  geom_density(alpha = 0.3) + 
  scale_x_continuous() + 
  geom_vline(data = means, aes(xintercept = price, color = cut), linetype = 2, show_guide = TRUE) + 
  scale_fill_manual(name = "", 
                    values=c('red','blue'), 
                    labels = c("Premium", "Ideal")) +
  scale_color_hue(name = " ",  
                  labels = c("Mean", "Mean")) +
  theme(legend.box = 'horizontal', 
        legend.position = c(0.75, 0.75)) + 
  guides(fill = guide_legend(override.aes = list(linetype = 0)))
Adding extra information to dygraph legend?

Adding extra information to dygraph legend?


By : salideng
Date : March 29 2020, 07:55 AM
hop of those help? The easiest way to do this is with the legendFormatter option in the upcoming 2.0.0 release:
code :
function legendFormatter(data) {
  if (data.x == null) return '';  // no selection
  return data.xHTML +
      data.series
      .map(v => v.labelHTML + ': ' + v.yHTML)  // modify as needed
      .join(' ');
}

new Dygraph(div, data, { legendFormatter });
Highcharts: Adding extra text to legend

Highcharts: Adding extra text to legend


By : Kurt Slagle
Date : March 29 2020, 07:55 AM
To fix the issue you can do You can add some if condition and display text like you want.
e.g.
Adding extra legend information using ggplot2

Adding extra legend information using ggplot2


By : J'Shan
Date : March 29 2020, 07:55 AM
help you fix your problem I'm not quite sure what you mean with to add a legend line. Do you maybe mean that you want a key in the legend for the dots that co-exists with the keys of the preprocessing steps?
If that is the case I would recommend mapping the geom_point() colour to a variable, which can exist outside any data.frame:
code :
ggplot() + 
  geom_bar(aes(fill=columns, y=diffs, x=samps), stat="identity", position="fill") + 
  scale_fill_discrete(name="Preprocessing Steps",labels=labels,
                      # Order set to 1 to appear before dot
                      guide = guide_legend(order = 1)) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  xlab("Samples") + ylab("Fractions of all reads") +
  # Add a colour mapping
  geom_point(data=dffs, aes(x=x,y=y, colour = "Recorded\nContaminant\nValues")) +
  # You can colour the dot how you like
  scale_colour_manual(values = "red", name = "")
shadow
Privacy Policy - Terms - Contact Us © voile276.org