Reorder X-axis categories and separating legend with ggplot2
up vote
0
down vote
favorite
Brand new to using R and ggplot2 so please forgive the funkiness of my code.
I'm trying to preserve the order of my x-axis from a csv file, but it was reordered alphabetically.
I attempted to use scale_x_discrete
, but I think my implementation was poor or perhaps it was inappropriate to use.
The result was a reordered x-axis, but the plotted points were preserved in the alphabetical order. Additionally, my legend is incorporating my weighted average. I would like to have a standalone third legend that defines the red X. How would I go about separating the geom layers of the same type?
#Main plot
myplot <- ggplot(mydata, aes(x = treatment, y = delta_ases)) + #plot treatment(x) vs score(y)
geom_point(aes(size = sample_size)) + #adjust point area by sample size
geom_point(aes(y=ases_weighted_avg, size=30),
color="red", shape=4) + #plot weighted average, show.legend = FALSE?
scale_y_continuous(breaks = seq(0, 100, by = 10),
limits = c(5, 75)) + #cleaner y-axis
theme_bw() +
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black")) #remove background and grid elements
myplot <- myplot + labs(x = "Treatment Strategy") + #rename x-axis
labs(y = "Change in ASES Score") + #rename y-axis
labs(size = "Sample Size") + #rename sample size legend
labs(linetype = "MCID") + #rename line legend
geom_hline(aes(yintercept = 17, linetype = "PT"),
color = 'black') + #create horizontal line for Physical Therapy Group
geom_hline(aes(yintercept = 39, linetype = "Surgery"),
color = 'black') #create horizontal line for Surgical Group
myplot
Sample Data
structure(list(treatment = structure(c(5L, 5L, 5L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 7L, 1L, 1L, 6L, 6L, 6L,
6L, 6L, 6L), .Label = c("BA", "D", "GI", "PR", "PT", "RSA", "SCR",
"TT"), class = "factor"), sample_size = c(30L, 45L, 19L, 33L,
23L, 41L, 33L, 57L, 31L, 38L, 13L, 90L, 37L, 22L, 28L, 11L, 25L,
5L, 21L, 41L, 27L, 14L, 86L, 33L, 55L, 67L, 55L, 52L, 15L, 60L,
42L, 36L, 23L, 5L, 20L, 64L, 17L, 58L, 25L, 49L, 34L), delta_ases = c(23,
NA, NA, 28, NA, NA, NA, NA, 45.8, NA, NA, NA, 32.6, NA, 32.7,
NA, 39.1, 45, NA, NA, NA, NA, 40.1, NA, NA, NA, NA, NA, NA, NA,
24.9, 35.8, 69.4, NA, NA, 32.4, NA, 42.1, NA, NA, NA), delta_cms = c(NA,
13, NA, 21, 31.4, 28, 30, NA, 16.8, NA, 27.7, 37.2, NA, 30.9,
NA, NA, NA, NA, 37.8, 46.4, 34, 26, 25.9, NA, 16.5, 14, 28.4,
36, 38.7, 28.5, 27.4, NA, NA, 25, 33.2, NA, NA, NA, 28.4, 36.7,
35.6), ases_weighted_avg = c(23, NA, NA, 36.621875, NA, NA, NA,
NA, NA, NA, 34.43666667, NA, NA, NA, NA, NA, NA, 45, NA, NA,
35.1125, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 48.89830508,
NA, NA, NA, 37.01147541, NA, NA, NA, NA, NA), cms_weighted_avg = c(NA,
13, NA, 25.30434783, NA, NA, NA, NA, NA, NA, 35.1032, NA, NA,
NA, NA, NA, NA, 43.48709677, NA, NA, 25.85665962, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 31.56, NA, 34.43240741, NA,
NA, NA, NA, NA)), class = "data.frame", row.names = c(NA, -41L
))
r ggplot2
add a comment |
up vote
0
down vote
favorite
Brand new to using R and ggplot2 so please forgive the funkiness of my code.
I'm trying to preserve the order of my x-axis from a csv file, but it was reordered alphabetically.
I attempted to use scale_x_discrete
, but I think my implementation was poor or perhaps it was inappropriate to use.
The result was a reordered x-axis, but the plotted points were preserved in the alphabetical order. Additionally, my legend is incorporating my weighted average. I would like to have a standalone third legend that defines the red X. How would I go about separating the geom layers of the same type?
#Main plot
myplot <- ggplot(mydata, aes(x = treatment, y = delta_ases)) + #plot treatment(x) vs score(y)
geom_point(aes(size = sample_size)) + #adjust point area by sample size
geom_point(aes(y=ases_weighted_avg, size=30),
color="red", shape=4) + #plot weighted average, show.legend = FALSE?
scale_y_continuous(breaks = seq(0, 100, by = 10),
limits = c(5, 75)) + #cleaner y-axis
theme_bw() +
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black")) #remove background and grid elements
myplot <- myplot + labs(x = "Treatment Strategy") + #rename x-axis
labs(y = "Change in ASES Score") + #rename y-axis
labs(size = "Sample Size") + #rename sample size legend
labs(linetype = "MCID") + #rename line legend
geom_hline(aes(yintercept = 17, linetype = "PT"),
color = 'black') + #create horizontal line for Physical Therapy Group
geom_hline(aes(yintercept = 39, linetype = "Surgery"),
color = 'black') #create horizontal line for Surgical Group
myplot
Sample Data
structure(list(treatment = structure(c(5L, 5L, 5L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 7L, 1L, 1L, 6L, 6L, 6L,
6L, 6L, 6L), .Label = c("BA", "D", "GI", "PR", "PT", "RSA", "SCR",
"TT"), class = "factor"), sample_size = c(30L, 45L, 19L, 33L,
23L, 41L, 33L, 57L, 31L, 38L, 13L, 90L, 37L, 22L, 28L, 11L, 25L,
5L, 21L, 41L, 27L, 14L, 86L, 33L, 55L, 67L, 55L, 52L, 15L, 60L,
42L, 36L, 23L, 5L, 20L, 64L, 17L, 58L, 25L, 49L, 34L), delta_ases = c(23,
NA, NA, 28, NA, NA, NA, NA, 45.8, NA, NA, NA, 32.6, NA, 32.7,
NA, 39.1, 45, NA, NA, NA, NA, 40.1, NA, NA, NA, NA, NA, NA, NA,
24.9, 35.8, 69.4, NA, NA, 32.4, NA, 42.1, NA, NA, NA), delta_cms = c(NA,
13, NA, 21, 31.4, 28, 30, NA, 16.8, NA, 27.7, 37.2, NA, 30.9,
NA, NA, NA, NA, 37.8, 46.4, 34, 26, 25.9, NA, 16.5, 14, 28.4,
36, 38.7, 28.5, 27.4, NA, NA, 25, 33.2, NA, NA, NA, 28.4, 36.7,
35.6), ases_weighted_avg = c(23, NA, NA, 36.621875, NA, NA, NA,
NA, NA, NA, 34.43666667, NA, NA, NA, NA, NA, NA, 45, NA, NA,
35.1125, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 48.89830508,
NA, NA, NA, 37.01147541, NA, NA, NA, NA, NA), cms_weighted_avg = c(NA,
13, NA, 25.30434783, NA, NA, NA, NA, NA, NA, 35.1032, NA, NA,
NA, NA, NA, NA, 43.48709677, NA, NA, 25.85665962, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 31.56, NA, 34.43240741, NA,
NA, NA, NA, NA)), class = "data.frame", row.names = c(NA, -41L
))
r ggplot2
In order for people to help you please post a sample of your data so we can reproduce this
– Mike
Nov 9 at 18:21
Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not usestr()
,head()
or screenshot)? You can use thereprex
anddatapasta
packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?
– Tung
Nov 9 at 18:50
Like Tung suggested, please don't usehead()
, present the data so that others can easily enter it by copying code, like withdput()
.
– Anonymous coward
Nov 9 at 19:08
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Brand new to using R and ggplot2 so please forgive the funkiness of my code.
I'm trying to preserve the order of my x-axis from a csv file, but it was reordered alphabetically.
I attempted to use scale_x_discrete
, but I think my implementation was poor or perhaps it was inappropriate to use.
The result was a reordered x-axis, but the plotted points were preserved in the alphabetical order. Additionally, my legend is incorporating my weighted average. I would like to have a standalone third legend that defines the red X. How would I go about separating the geom layers of the same type?
#Main plot
myplot <- ggplot(mydata, aes(x = treatment, y = delta_ases)) + #plot treatment(x) vs score(y)
geom_point(aes(size = sample_size)) + #adjust point area by sample size
geom_point(aes(y=ases_weighted_avg, size=30),
color="red", shape=4) + #plot weighted average, show.legend = FALSE?
scale_y_continuous(breaks = seq(0, 100, by = 10),
limits = c(5, 75)) + #cleaner y-axis
theme_bw() +
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black")) #remove background and grid elements
myplot <- myplot + labs(x = "Treatment Strategy") + #rename x-axis
labs(y = "Change in ASES Score") + #rename y-axis
labs(size = "Sample Size") + #rename sample size legend
labs(linetype = "MCID") + #rename line legend
geom_hline(aes(yintercept = 17, linetype = "PT"),
color = 'black') + #create horizontal line for Physical Therapy Group
geom_hline(aes(yintercept = 39, linetype = "Surgery"),
color = 'black') #create horizontal line for Surgical Group
myplot
Sample Data
structure(list(treatment = structure(c(5L, 5L, 5L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 7L, 1L, 1L, 6L, 6L, 6L,
6L, 6L, 6L), .Label = c("BA", "D", "GI", "PR", "PT", "RSA", "SCR",
"TT"), class = "factor"), sample_size = c(30L, 45L, 19L, 33L,
23L, 41L, 33L, 57L, 31L, 38L, 13L, 90L, 37L, 22L, 28L, 11L, 25L,
5L, 21L, 41L, 27L, 14L, 86L, 33L, 55L, 67L, 55L, 52L, 15L, 60L,
42L, 36L, 23L, 5L, 20L, 64L, 17L, 58L, 25L, 49L, 34L), delta_ases = c(23,
NA, NA, 28, NA, NA, NA, NA, 45.8, NA, NA, NA, 32.6, NA, 32.7,
NA, 39.1, 45, NA, NA, NA, NA, 40.1, NA, NA, NA, NA, NA, NA, NA,
24.9, 35.8, 69.4, NA, NA, 32.4, NA, 42.1, NA, NA, NA), delta_cms = c(NA,
13, NA, 21, 31.4, 28, 30, NA, 16.8, NA, 27.7, 37.2, NA, 30.9,
NA, NA, NA, NA, 37.8, 46.4, 34, 26, 25.9, NA, 16.5, 14, 28.4,
36, 38.7, 28.5, 27.4, NA, NA, 25, 33.2, NA, NA, NA, 28.4, 36.7,
35.6), ases_weighted_avg = c(23, NA, NA, 36.621875, NA, NA, NA,
NA, NA, NA, 34.43666667, NA, NA, NA, NA, NA, NA, 45, NA, NA,
35.1125, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 48.89830508,
NA, NA, NA, 37.01147541, NA, NA, NA, NA, NA), cms_weighted_avg = c(NA,
13, NA, 25.30434783, NA, NA, NA, NA, NA, NA, 35.1032, NA, NA,
NA, NA, NA, NA, 43.48709677, NA, NA, 25.85665962, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 31.56, NA, 34.43240741, NA,
NA, NA, NA, NA)), class = "data.frame", row.names = c(NA, -41L
))
r ggplot2
Brand new to using R and ggplot2 so please forgive the funkiness of my code.
I'm trying to preserve the order of my x-axis from a csv file, but it was reordered alphabetically.
I attempted to use scale_x_discrete
, but I think my implementation was poor or perhaps it was inappropriate to use.
The result was a reordered x-axis, but the plotted points were preserved in the alphabetical order. Additionally, my legend is incorporating my weighted average. I would like to have a standalone third legend that defines the red X. How would I go about separating the geom layers of the same type?
#Main plot
myplot <- ggplot(mydata, aes(x = treatment, y = delta_ases)) + #plot treatment(x) vs score(y)
geom_point(aes(size = sample_size)) + #adjust point area by sample size
geom_point(aes(y=ases_weighted_avg, size=30),
color="red", shape=4) + #plot weighted average, show.legend = FALSE?
scale_y_continuous(breaks = seq(0, 100, by = 10),
limits = c(5, 75)) + #cleaner y-axis
theme_bw() +
theme(panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black")) #remove background and grid elements
myplot <- myplot + labs(x = "Treatment Strategy") + #rename x-axis
labs(y = "Change in ASES Score") + #rename y-axis
labs(size = "Sample Size") + #rename sample size legend
labs(linetype = "MCID") + #rename line legend
geom_hline(aes(yintercept = 17, linetype = "PT"),
color = 'black') + #create horizontal line for Physical Therapy Group
geom_hline(aes(yintercept = 39, linetype = "Surgery"),
color = 'black') #create horizontal line for Surgical Group
myplot
Sample Data
structure(list(treatment = structure(c(5L, 5L, 5L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 7L, 7L, 1L, 1L, 6L, 6L, 6L,
6L, 6L, 6L), .Label = c("BA", "D", "GI", "PR", "PT", "RSA", "SCR",
"TT"), class = "factor"), sample_size = c(30L, 45L, 19L, 33L,
23L, 41L, 33L, 57L, 31L, 38L, 13L, 90L, 37L, 22L, 28L, 11L, 25L,
5L, 21L, 41L, 27L, 14L, 86L, 33L, 55L, 67L, 55L, 52L, 15L, 60L,
42L, 36L, 23L, 5L, 20L, 64L, 17L, 58L, 25L, 49L, 34L), delta_ases = c(23,
NA, NA, 28, NA, NA, NA, NA, 45.8, NA, NA, NA, 32.6, NA, 32.7,
NA, 39.1, 45, NA, NA, NA, NA, 40.1, NA, NA, NA, NA, NA, NA, NA,
24.9, 35.8, 69.4, NA, NA, 32.4, NA, 42.1, NA, NA, NA), delta_cms = c(NA,
13, NA, 21, 31.4, 28, 30, NA, 16.8, NA, 27.7, 37.2, NA, 30.9,
NA, NA, NA, NA, 37.8, 46.4, 34, 26, 25.9, NA, 16.5, 14, 28.4,
36, 38.7, 28.5, 27.4, NA, NA, 25, 33.2, NA, NA, NA, 28.4, 36.7,
35.6), ases_weighted_avg = c(23, NA, NA, 36.621875, NA, NA, NA,
NA, NA, NA, 34.43666667, NA, NA, NA, NA, NA, NA, 45, NA, NA,
35.1125, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 48.89830508,
NA, NA, NA, 37.01147541, NA, NA, NA, NA, NA), cms_weighted_avg = c(NA,
13, NA, 25.30434783, NA, NA, NA, NA, NA, NA, 35.1032, NA, NA,
NA, NA, NA, NA, 43.48709677, NA, NA, 25.85665962, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, 31.56, NA, 34.43240741, NA,
NA, NA, NA, NA)), class = "data.frame", row.names = c(NA, -41L
))
r ggplot2
r ggplot2
edited Nov 9 at 22:20
s_t
2,9552928
2,9552928
asked Nov 9 at 17:55
Sai T.
104
104
In order for people to help you please post a sample of your data so we can reproduce this
– Mike
Nov 9 at 18:21
Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not usestr()
,head()
or screenshot)? You can use thereprex
anddatapasta
packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?
– Tung
Nov 9 at 18:50
Like Tung suggested, please don't usehead()
, present the data so that others can easily enter it by copying code, like withdput()
.
– Anonymous coward
Nov 9 at 19:08
add a comment |
In order for people to help you please post a sample of your data so we can reproduce this
– Mike
Nov 9 at 18:21
Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not usestr()
,head()
or screenshot)? You can use thereprex
anddatapasta
packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?
– Tung
Nov 9 at 18:50
Like Tung suggested, please don't usehead()
, present the data so that others can easily enter it by copying code, like withdput()
.
– Anonymous coward
Nov 9 at 19:08
In order for people to help you please post a sample of your data so we can reproduce this
– Mike
Nov 9 at 18:21
In order for people to help you please post a sample of your data so we can reproduce this
– Mike
Nov 9 at 18:21
Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use
str()
, head()
or screenshot)? You can use the reprex
and datapasta
packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?– Tung
Nov 9 at 18:50
Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use
str()
, head()
or screenshot)? You can use the reprex
and datapasta
packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?– Tung
Nov 9 at 18:50
Like Tung suggested, please don't use
head()
, present the data so that others can easily enter it by copying code, like with dput()
.– Anonymous coward
Nov 9 at 19:08
Like Tung suggested, please don't use
head()
, present the data so that others can easily enter it by copying code, like with dput()
.– Anonymous coward
Nov 9 at 19:08
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You'll have to define that shape separately.
d <- ggplot(mydata, aes(x = factor(treatment, levels = c("PT", "D", "PR", "GI")), y = delta_ases, size = sample_size)) +
geom_point()
d + geom_point(aes(y = ases_weighted_avg, shape = "mean"), geom = "point", size = 6, color = "red") +
guides(size = guide_legend(order = 1)) + scale_shape_manual("", values = c("mean" = "x"))
Add in your themes and labels.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230993%2freorder-x-axis-categories-and-separating-legend-with-ggplot2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You'll have to define that shape separately.
d <- ggplot(mydata, aes(x = factor(treatment, levels = c("PT", "D", "PR", "GI")), y = delta_ases, size = sample_size)) +
geom_point()
d + geom_point(aes(y = ases_weighted_avg, shape = "mean"), geom = "point", size = 6, color = "red") +
guides(size = guide_legend(order = 1)) + scale_shape_manual("", values = c("mean" = "x"))
Add in your themes and labels.
add a comment |
up vote
0
down vote
accepted
You'll have to define that shape separately.
d <- ggplot(mydata, aes(x = factor(treatment, levels = c("PT", "D", "PR", "GI")), y = delta_ases, size = sample_size)) +
geom_point()
d + geom_point(aes(y = ases_weighted_avg, shape = "mean"), geom = "point", size = 6, color = "red") +
guides(size = guide_legend(order = 1)) + scale_shape_manual("", values = c("mean" = "x"))
Add in your themes and labels.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You'll have to define that shape separately.
d <- ggplot(mydata, aes(x = factor(treatment, levels = c("PT", "D", "PR", "GI")), y = delta_ases, size = sample_size)) +
geom_point()
d + geom_point(aes(y = ases_weighted_avg, shape = "mean"), geom = "point", size = 6, color = "red") +
guides(size = guide_legend(order = 1)) + scale_shape_manual("", values = c("mean" = "x"))
Add in your themes and labels.
You'll have to define that shape separately.
d <- ggplot(mydata, aes(x = factor(treatment, levels = c("PT", "D", "PR", "GI")), y = delta_ases, size = sample_size)) +
geom_point()
d + geom_point(aes(y = ases_weighted_avg, shape = "mean"), geom = "point", size = 6, color = "red") +
guides(size = guide_legend(order = 1)) + scale_shape_manual("", values = c("mean" = "x"))
Add in your themes and labels.
answered Nov 9 at 19:06
Anonymous coward
1,3941919
1,3941919
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230993%2freorder-x-axis-categories-and-separating-legend-with-ggplot2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
In order for people to help you please post a sample of your data so we can reproduce this
– Mike
Nov 9 at 18:21
Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use
str()
,head()
or screenshot)? You can use thereprex
anddatapasta
packages to assist you with that. See also Help me Help you & How to make a great R reproducible example?– Tung
Nov 9 at 18:50
Like Tung suggested, please don't use
head()
, present the data so that others can easily enter it by copying code, like withdput()
.– Anonymous coward
Nov 9 at 19:08