logo
down
shadow

ggplot: How to keep marker colours in legend but hide text colours?


ggplot: How to keep marker colours in legend but hide text colours?

Content Index :

ggplot: How to keep marker colours in legend but hide text colours?
Tag : r , By : Marc
Date : November 23 2020, 04:01 AM

help you fix your problem You may specify the breaks manually too by the replacing the last line with
scale_colour_manual(breaks = c("a", "b"), values = c("salmon", "black", "salmon", "darkturquoise"))

Comments
No Comments Right Now !

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

Share : facebook icon twitter icon

Python graph- change axis marker colours and legend border colours


Tag : python , By : Michael Gunderson
Date : March 29 2020, 07:55 AM
wish of those help If you just want to use rcParams, the proper parameters are xticks.color and yticks.color. I can't seem to find a key for the legend frame color. You can set that (along with the tick colors) programmatically though.
import pylab

pylab.plot([1,2,3],[4,5,6], label ='test')
lg = pylab.legend()
lg.get_frame().set_edgecolor('blue')
ax = pylab.axes()

for line in ax.yaxis.get_ticklines():
    line.set_color('blue')
for line in ax.xaxis.get_ticklines():
    line.set_color('blue')

for label in ax.yaxis.get_ticklabels():
    label.set_color('blue')
for label in ax.xaxis.get_ticklabels():
    label.set_color('blue')

pylab.show()

Optimal visualisation of ggplot colours: changing order of colours, keeping original factor ordering


Tag : r , By : simonth
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I love the default ggplot2 colour, but with the dataset I'm using, it's very important the reader can tell the difference between two adjacent categories. This is difficult with the default colours, as I have 10 categories and therefore the generated colours are very similar between neighbouring factor groups. , To shuffle the order of the colors, you could use
require(scales)
n <- length(levels(data$category)) # number of colors
cols <- hue_pal(h = c(0, 360) + 15, 
                c = 100, l = 65, 
                h.start = 0, direction = 1)(n)[order(sample(1:n, n))] # color palette in random order
ggplot(data,aes(x,y,colour=category))+stat_smooth(alpha=0, size=2) + 
  scale_color_manual(values = cols) 

ggplot legend colours in complex plot


Tag : r , By : Daniel Halsey
Date : March 29 2020, 07:55 AM
Does that help Change the colour= call in aes in the geom_line calls to whatever you want to appear in the legend:
add_lines1 <- lapply(s1, function(i) geom_line(aes_q(y = as.name(i), colour = "Line1")))
add_lines2 <- lapply(s2, function(i) geom_line(aes_q(y = as.name(i), colour = "Line2")))
add_lines3 <- lapply(s3, function(i) geom_line(aes_q(y = as.name(i), colour = "Line3")))
add_lines4 <- lapply(s4, function(i) geom_line(aes_q(y = as.name(i), colour = "Line4")))
p1 <- ggplot(data, aes(x = time)) + scale_color_manual(values=c("orange","yellow","white","green"))
p1 <- p1 + add_lines1 + add_lines2

p2 <- ggplot(data, aes(x = time)) + scale_color_manual(values=c("orange","yellow","white","green"))
p2 <- p2 + add_lines1 + add_lines3 + add_lines4

how to add legend to ggplot barplot with individual colours for each bar


Tag : r , By : unfool
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I'm new to ggplot, so hopefully this is an easy question. I've made a stacked barplot with colours for each segment given in col: , You were close!
Move fill = col to aes:
library(ggplot2)
a <- data.frame(var = rep(seq(1:2),2), val = seq(1:4))
col <- rainbow(n = 4)
ggplot(a, aes(x = var, y = val, fill = col)) +
    geom_bar(stat = 'identity') +
    scale_fill_manual(values = col)

My figure legend colours do not match my graph line colours?


Tag : python , By : tayles
Date : March 29 2020, 07:55 AM
this will help You are basically plotting the error bar over the inital line plot. As default the plt.errorbar is a line plot with error bar on each point.
# Gives a red line plot
plot1, = plt.plot(x, b, 'r-')
# Gives a '#1f77b4' (default first color) line plot with error bars
plt.errorbar(x, b, xerr=None, yerr=mated_E)
import pandas as pd
import matplotlib.pyplot as plt

df_mated = pd.read_csv("file1.txt", sep='\t', header=0)   
df_mated['Average'] = df_mated.mean(axis=1)
df_mated['SEM'] = df_mated.loc[:, :'Average'].sem()
mated_E = df_mated['SEM'].tolist()
b = df_mated['Average'].tolist()
plot1, = plt.plot(x, b, 'r-')
# Plot only the y-errorbar, not the line connecting the datapoint
plt.errorbar(x, b, xerr=None, yerr=mated_E, ls='')

df_unmated = pd.read_csv("file2.txt", sep='\t', header=0) 
df_unmated['Average'] = df_unmated.mean(axis=1)
df_unmated['SEM'] = df_unmated.loc[:, :'Average'].sem()
unmated_E = df_unmated['SEM'].tolist()
c = df_unmated['Average'].tolist()
plot2, = plt.plot(x, c, 'b-')
# Plot only the y-errorbar, not the line connecting the datapoint
plt.errorbar(x, c, xerr=None, yerr=unmated_E, ls='')

plt.xlabel('Position')
plt.ylabel('Average Read Depth')
plt.legend([plot1,plot2],["Mated", "Unmated"])
plt.show()
Related Posts Related QUESTIONS :
  • calculate number and names of similar sounding words from a data frame
  • Reset input fields of dynamically generated widgets through insertUI
  • How to get the coordinates that spits out min/max value from the function in R?
  • running t.test() on multiple columns to output tibble
  • Conditionally replace the values in columns to value in another column using dplyr
  • Add count as label to points in geom_count
  • 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
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com