Как изменить легенду (метки и цвет), чтобы высокое значение начиналось снизу?

Каков наилучший способ инвертировать порядок меток легенды, чтобы 7 было внизу, а 1 - наверху?

вызов легенды ggplot

df$day <- as.numeric(df3$day)
blues <- colorRampPalette(c('#132B43', '#56B1F7'))

p4 <- 
    ggplot(subset(df,feedback==1&stp>20), aes(x=correct, fill=day, colour=day)) +
    geom_histogram(colour="black", binwidth=10) +
    facet_grid(day ~ .) +
    ggtitle("Over-pronation histogram") +
    ylab("Count (150s period)") +
    xlab("% Steps in over-pronation") +guide_legend(reverse = false)

person Community    schedule 17.03.2014    source источник
comment
ты пробовал guide_legend(reverse = TRUE)?   -  person Harpal    schedule 17.03.2014
comment
пробовал конечно. нет эффекта.   -  person    schedule 19.03.2014
comment
набор данных: код dropbox.com/s/5vfjk5kpvfv1vqe/_logs9.csv: dropbox.com/s/b0ckwshfs3ipq57/_embspaper.R   -  person    schedule 19.03.2014


Ответы (3)


Ваш код довольно странный, с false вместо FALSE и неправильно расположенным guide_legend. Правильное использование: (@Harpal дает намёк на это):

ggplot(data.frame(x=1:4, y=4:1, col=factor(1:4)), aes(x=x, y=y, col=col)) + 
  geom_point(size=10)
ggplot(data.frame(x=1:4, y=4:1, col=factor(1:4)), aes(x=x, y=y, col=col)) + 
  geom_point(size=10) + guides(colour = guide_legend(reverse=T))

введите здесь описание изображениявведите здесь описание изображения

person tonytonov    schedule 18.03.2014

Если вы указываете числовое значение, и это непрерывная шкала, вам лучше использовать scale_fill_continuous(trans = 'reverse') или scale_colour_continuous. Используя ваш код, это даст:

ggplot(subset(df,feedback==1&stp>20), aes(x=correct, fill=day, colour=day)) +
    geom_histogram(colour="black", binwidth=10) +
    facet_grid(day ~ .) +
    ggtitle("Over-pronation histogram") +
    ylab("Count (150s period)") +
    xlab("% Steps in over-pronation")+
    scale_fill_continuous(trans = 'reverse')
person dmt    schedule 22.07.2014

Для непрерывных шкал требуется guide_colorbar.

Здесь я меняю направление цвета. Затем я изменяю порядок цвета и размера с помощью разных функций.

library(tidyverse)
library(janitor)
iris %>% 
  as_tibble() %>% 
  clean_names() %>% 
  ggplot(aes(x = sepal_length,
             y = petal_width,
             size = sepal_width,
             color = petal_length)) +
  geom_point() +
  facet_wrap(~species,scales = "free") +
  #reverse color direction (the higher in value, the darker in color)
  scale_color_continuous(trans = 'reverse') +
  #edit legends
  guides(
    #reverse color order (higher value on top)
    color = guide_colorbar(reverse = TRUE),
    #reverse size order (higher diameter on top) 
    size = guide_legend(reverse = TRUE))
person avallecam    schedule 08.08.2019