Shape legend ggplot

I'm trying to make my shape legend right yet I cannot find the way. I will appreciate your help!

ata <-  structure(list(CZE = c("Rakousko", "Rakousko", "Rakousko", "Rakousko", 
                                "Belgie", "Belgie", "Belgie", "Belgie", "Česká rep.", "Česká rep.", 
                                "Česká rep.", "Česká rep.", "Dánsko", "Dánsko", "Dánsko", 
                                "Dánsko", "Finsko", "Finsko", "Finsko", "Finsko", "Francie", 
                                "Francie", "Francie", "Francie", "Německo", "Německo", "Německo", 
                                "Německo", "Řecko", "Řecko", "Řecko", "Řecko", "Maďarsko", 
                                "Maďarsko", "Maďarsko", "Maďarsko", "Irsko", "Irsko", "Irsko", 
                                "Irsko", "Itálie", "Itálie", "Itálie", "Itálie", "Lucembursko", 
                                "Lucembursko", "Lucembursko", "Lucembursko", "Nizozemsko", "Nizozemsko", 
                                "Nizozemsko", "Nizozemsko", "Polsko", "Polsko", "Polsko", "Polsko", 
                                "Portugalsko", "Portugalsko", "Portugalsko", "Portugalsko", "Slovensko", 
                                "Slovensko", "Slovensko", "Slovensko", "Španělsko", "Španělsko", 
                                "Španělsko", "Španělsko", "Švédsko", "Švédsko", "Švédsko", 
                                "Švédsko", "Estonsko", "Estonsko", "Estonsko", "Estonsko", 
                                "Slovinsko", "Slovinsko", "Slovinsko", "Slovinsko", "Lotyšsko", 
                                "Lotyšsko", "Lotyšsko", "Lotyšsko", "Litva", "Litva", "Litva", 
                                "Litva"), value = c(5.9870548248, 6.3483529091, 5.1097159386, 
                                                    5.4881105423, 10.662885666, 11.620417595, 7.0958051682, 7.3251843452, 
                                                    12.868912697, 15.647431374, 6.742125988, 9.8579006195, 5.0980668068, 
                                                    5.0955414772, 2.3525671959, 3.3858146667, 10.545541763, 9.8487854004, 
                                                    5.9297027588, 6.4263458252, 7.2869539261, 8.717625618, 3.7775719166, 
                                                    6.365963459, 5.7187438011, 4.5645136833, 3.723549366, 3.6520648003, 
                                                    27.074705124, 23.521549225, 17.463827133, 16.197927475, 11.704945564, 
                                                    7.8512573242, 6.500058651, 5.7065634727, 15.62046814, 11.62810421, 
                                                    4.167907238, 5, 13.233427048, 17.141275406, 7.5290389061, 11.257595062, 
                                                    3.1164069176, 4.7188105583, 2.2598869801, 4.2867698669, 7.5726628304, 
                                                    13.444386482, 5.8907790184, 10.414941788, 20.362581253, 17.898298264, 
                                                    15.013916016, 9.8211803436, 13.877723694, 10.528628349, 14.606637001, 
                                                    7.7351212502, 7.4625535011, 15.216593742, 2.5922441483, 7.9442572594, 
                                                    13.772670746, 12.86302948, 9.5293941498, 8.4657001495, 8.2130432129, 
                                                    6.8584413528, 3.5104801655, 3.496322155, 5.3546590805, 7.0729393959, 
                                                    3.9561991692, 4.2740840912, 8.9205875397, 9.2440195084, 4.1180849075, 
                                                    5.9927635193, 6.5694971085, 8.1411762238, 5.5755395889, 6.9070472717, 
                                                    16.989721298, 11.063240051, 11.003282547, 6.5771188736), SUBJECT = c("MEN", 
                                                                                                                         "MEN", "WOMEN", "WOMEN", "MEN", "MEN", "WOMEN", "WOMEN", "MEN", 
                                                                                                                         "MEN", "WOMEN", "WOMEN", "MEN", "MEN", "WOMEN", "WOMEN", "MEN", 
                                                                                                                         "MEN", "WOMEN", "WOMEN", "MEN", "MEN", "WOMEN", "WOMEN", "MEN", 
                                                                                                                         "MEN", "WOMEN", "WOMEN", "MEN", "MEN", "WOMEN", "WOMEN", "MEN", 
                                                                                                                         "MEN", "WOMEN", "WOMEN", "MEN", "MEN", "WOMEN", "WOMEN", "MEN", 
                                                                                                                         "MEN", "WOMEN", "WOMEN", "MEN", "MEN", "WOMEN", "WOMEN", "MEN", 
                                                                                                                         "MEN", "WOMEN", "WOMEN", "MEN", "MEN", "WOMEN", "WOMEN", "MEN", 
                                                                                                                         "MEN", "WOMEN", "WOMEN", "MEN", "MEN", "WOMEN", "WOMEN", "MEN", 
                                                                                                                         "MEN", "WOMEN", "WOMEN", "MEN", "MEN", "WOMEN", "WOMEN", "MEN", 
                                                                                                                         "MEN", "WOMEN", "WOMEN", "MEN", "MEN", "WOMEN", "WOMEN", "MEN", 
                                                                                                                         "MEN", "WOMEN", "WOMEN", "MEN", "MEN", "WOMEN", "WOMEN"), TIME = c(2000, 
                                                                                                                                                                                            2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 
                                                                                                                                                                                            2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 
                                                                                                                                                                                            2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 
                                                                                                                                                                                            2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 
                                                                                                                                                                                            2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 
                                                                                                                                                                                            2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 
                                                                                                                                                                                            2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 
                                                                                                                                                                                            2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020, 2000, 2020)), row.names = c(NA, 
                                                                                                                                                                                                                                                                        -88L), class = c("tbl_df", "tbl", "data.frame"))


library(ggplot2)

ggplot(data, aes(y = reorder(CZE, value), x = value, fill = SUBJECT,
                 color = SUBJECT, shape = factor(TIME))) +
  geom_point(size = 3) +
  scale_fill_manual(values = c("#ECB925", "#00254B")) +
  scale_color_manual(values = c("#ECB925", "#00254B"),
                     labels = c("muži", "ženy")) +
  scale_shape_manual(values = c(5, 23),
                     labels = c("2000", "2020")) +
  theme_minimal() + 
  theme(
    legend.position = 'bottom',
    legend.margin = margin(0, 0, 0, 0),
    legend.title = element_blank(),
    text = element_text(size = 15),
    axis.text.x = element_text(size = 13),
    axis.text.y = element_text(
      size = 13,
      angle = 0,
      hjust = 0.7,
      face = ifelse(unique(data$CZE) == "Španělsko", "bold", "plain")
    ),
    axis.title.x = element_text(size = 11.5, 
                                margin = margin(10,0,0,0)),
    plot.margin = margin(20, 20, 20, 20),
    axis.title.y = element_blank(),
    panel.spacing = unit(2, "lines"),
    panel.grid.major.y = element_blank()
  ) +
  scale_x_continuous(
    name = "OSVČ/(OSVČ + zaměstnanci)",
    label = scales::comma_format(
      accuracy = 1,
      scale = 1,
      prefix = "",
      suffix = " %",
      big.mark = " ",
      decimal.mark = ","
    )
  ) +
  guides(fill = "none")

What is wrong with the current version? Is something like this what you want?

data <- ...
library(ggplot2)

ggplot(data, aes(y = reorder(CZE, value), x = value,
                 fill = interaction(SUBJECT, factor(TIME)),
                 color = interaction(SUBJECT, factor(TIME)),
                 shape = interaction(SUBJECT, factor(TIME)))) +
  geom_point(size = 3) +
  scale_fill_manual(values = c("#ECB925", "#00254B", "#ECB925", "#00254B")) +
  scale_color_manual(values = c("#ECB925", "#00254B", "#ECB925", "#00254B")) +
  scale_shape_manual(values = c(5, 5, 23, 23, 23)) +
  theme_minimal() + 
  theme(
    legend.position = 'bottom',
    legend.margin = margin(0, 0, 0, 0),
    legend.title = element_blank(),
    text = element_text(size = 15),
    axis.text.x = element_text(size = 13),
    axis.text.y = element_text(
      size = 13,
      angle = 0,
      hjust = 0.7,
      face = ifelse(unique(data$CZE) == "Španělsko", "bold", "plain")
    ),
    axis.title.x = element_text(size = 11.5, 
                                margin = margin(10,0,0,0)),
    plot.margin = margin(20, 20, 20, 20),
    axis.title.y = element_blank(),
    panel.spacing = unit(2, "lines"),
    panel.grid.major.y = element_blank()
  ) +
  scale_x_continuous(
    name = "OSVČ/(OSVČ + zaměstnanci)",
    label = scales::comma_format(
      accuracy = 1,
      scale = 1,
      prefix = "",
      suffix = " %",
      big.mark = " ",
      decimal.mark = ","
    )
  )
#> Warning: Vectorized input to `element_text()` is not officially supported.
#> ℹ Results may be unexpected or may change in future versions of ggplot2.

Created on 2023-10-31 with reprex v2.0.2

If it is, the problem is that you need the mappings for shape, color and fill to map to the same variable. I did a quick-and-dirty version here with interaction(), you could do better with a mutate to define a variable with levels "men 2020", "women 2000" etc...

hey, sorry for insufficient clarity.

I just want to have 'filled' triangle next to '2020'.

Many thanks!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.