-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom label colours in geom_label_repel using hex codes #82
Comments
No matter, solved it myself using a combination of
|
Thanks for posting your problem, a figure, and your solution! It turns out that this issue is not related to ggrepel specifically, but applies to any ggplot2 plot. Here's an example showing the two ways you used to specify colors. I hope it helps to clarify the issue. d <- structure(list(
team = structure(
c(1L, 2L, 4L, 5L, 6L),
.Label = c("AFC Bournemouth",
"Arsenal",
"Brighton & Hove Albion",
"Burnley",
"Chelsea",
"Crystal Palace",
"Everton",
"Huddersfield Town",
"Hull City",
"Leicester City",
"Liverpool",
"Manchester City",
"Manchester United",
"Middlesbrough",
"Newcastle United",
"Southampton",
"Stoke City",
"Sunderland",
"Swansea City",
"Tottenham Hotspur",
"Watford",
"West Bromwich Albion",
"West Ham United"),
class = "factor"),
col1 = structure(
c(15L, 18L, 8L, 5L, 11L),
.Label = c(
"#000000", "#0053A0", "#0054A6",
"#0072CE", "#034694", "#091453", "#274488", "#53162F", "#5CBFEB",
"#60223B", "#C4122E", "#D00027", "#DA020E", "#E03A3E", "#E62333",
"#EB172B", "#ED1A3B", "#EF0107", "#F5A12D", "#FBEE23", "#FF0000",
"#FFFFFF"),
class = "factor"),
col2 = structure(c(
1L, 4L, 7L, 9L, 5L),
.Label = c("#000000", "#001C58", "#0072CE", "#023474",
"#1B458F", "#5299C6", "#8CCCE5", "#FDBE11", "#FFFFFF"),
class = "factor"),
height = c(179.2, 179.3, 180.2, 181.5, 185.1),
fouls = c(368L,398L, 429L, 395L, 470L)),
.Names = c("team", "col1", "col2","y"),
row.names = c(NA, 5L),
class = "data.frame"
)
library(ggplot2) Example 1If you pass colors to # Here, we're passing the colors to the geom_point() function.
ggplot(d, aes(x = x, y = y)) +
geom_point(size = 5, pch = 21, stroke = 3, colour = d$col1, fill = d$col2) Example 2If you pass values to the # Here, we're passing the colors into the aes() function.
ggplot(d, aes(x = x, y = y, colour = col1, fill = col2)) +
geom_point(size = 5, pch = 21, stroke = 3) |
First of all: thanks for a great package, you've saved me endless annoyance and wasted time fiddling around with plot labels!
I'm trying to apply custom colours to my
gg_label_repel
boxes, labels and borders using hexadecimal codes stored in my dataset (each x,y pair has corresponding hex codescol1
,col2
).In vanilla ggplot I can colour the points how I want like so:
Producing a plot like this:

But when I try to colour the boxes and labels in
geom_label_repel
like so:I get this undesired result:

It looks like colour is being treated as a factor and the actual hexadecimal code not being parsed? I've tried specifying
fill = col1, colour = col2
in the ggplot aesthetics call, various arguments inscale_fill_manual
, and casting the variablescol1
andcol2
as a character but nothing has worked so far.Here's a sample of the data returned by
dput
:I've scoured the vignette and StackOverflow to not avail, but maybe I'm missing something obvious..
Thanks in advance!
The text was updated successfully, but these errors were encountered: