0

I have a table of persons with 983 obs. and 27 variables. I would like to create a boxplot where I have their marital status overlayed as a scatterplot, but when doing this, it also changes the color of the gender labels, and includes them as part of the list of gender. Here is my code:

# Import table
tblHoved <- read.delim2(
  file = "T2_alle_kriminelle_fra_T1.txt",
  header = TRUE
)

# Lag punktdiagram
dPunkt_KjoennAar <- ggplot(data = tblHoved) +  # ↓ To calculate age
  geom_boxplot(mapping = aes(x = KJONN, y = 1875-FAAR, colour = KJONN)) +
  geom_jitter(mapping = aes(x = KJONN, y = 1875-FAAR, colour = SIVST), size = 0.5) +
  labs(
    title = "Fangebefolkninga fordelt etter kjønn og alder, med sivilstand",
    x = "Kjønn",
    y = "Alder"
  )
dPunkt_KjoennAar

Instead of listing (in the plot’s legend) the various marital state options …

  • [nil], e[nke], f[raskilt], g[ift], s[eparert], ug[ift] =
  • [nil], widower, divorced, married, separated, unmarried,

… it also includes the gender specifications (k[vinne], m[ann] = woman, man). How can I make it colour only the dots, and have a separate colouring scheme for male/female?

Samples

Sample table

PERSNR  KJONN   FAMST           SIVST   YRKE                    FAAR
011     m       Varetægtsfange  ug      Kobber og blikkenslager 1853
012     m       Varetægtsfange  ug      Dagarbeider             1854
013     m       Varetægtsfange  ug      Skomager                1833
014     m       Varetægtsfange  ug      Sømand                  1854
015     m       Varetægtsfange  ug      Arbeider ved Ølbryggeri 1850
016     m       Varetægtsfange  g       Sømand                  1836
017     m       Varetægtsfange  ug      Skræddersvend           1847
018     m       Varetægtsfange  g       Malersvend              1843
019     m       Varetægtsfange  ug      Malersvend              1853
020     k       Varetægtsfange  g       Dagarbeiderske          1836
021     k       Straffange      ug      Havt Maanedscondition   1850
022     m       Varetægtsfange  g       Bygselmand              1820
023     m       Varetægtsfange  ug      Dagarbeider             1859
007     m       Arrestant       ug      Blikkenslager           1848

Sample image

enter image description here

Canned Man
  • 734
  • 1
  • 7
  • 26
  • Can you please use `dput()` to extract your sample data? this makes it easy to load into R. – epo3 Nov 30 '16 at 12:16
  • 1
    Don't include `colour = KJONN` in `geom_boxplot`. You can only map one thing to color. Just use x, or perhaps `fill` to map KJONN. – Axeman Nov 30 '16 at 12:25
  • There are too many personal identifiers for me to be comfortable extracting the data, unfortuantely. How do you use `dput()`? Can you select specific columns to include? I could not find anything in the documentation suggesting that’s possible. – Canned Man Nov 30 '16 at 13:03

0 Answers0