Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

Hi Intellipaat Community! I am basically trying to reorder the items in the attached legend to a specific order that I would like to input. The order is Distal, rTub, Mid, Prox.

I have already executed the order function and scale_y_discrete. Scale_y_discrete didn't work because the y-axis is graphing a count frequency, and the data is stored as the text seen in the legend. The code I'm executing is below:

p <- Scaphoid_dataF %>%

  ggplot( aes(x=Age, fill = FxLoc, order = )) +

  geom_histogram() +

  labs(y = "Count of Fractures", x = "Patient Age", title = "Frequency of Fractures vs Age")

p + theme_bw() + scale_fill_grey()

1 Answer

0 votes
by (108k points)

In R programming, for achieving that, you have to set the factor orders:

Scaphoid_dataF$Age <- factor(Scaphoid_dataF$Age,

                        levels = c("Distal", "rTub", "Mid", "Prox"),

                        ordered = TRUE)

Browse Categories

...