1

For today, I've been focusing on plotting my data. 4 have succeeded but the following one is quite troublesome. Let's say that my data frame is called test. Some test data:

          Date Persnr  Holiday     AmountHolidays
1   2011-01-01  55312  FALSE       3
2   2011-01-01  55316  FALSE       4
3   2011-01-01  55325  FALSE       1.5
4   2011-01-01  76065  "Christmas" 2
5   2011-01-01  71928  "Christmas" 0
6   2011-01-01  72558  FALSE       3
....
10  2013-01-02  55312  FALSE       10
11  2013-01-02  55316  "Summer"    3.5
12  2013-01-02  55325  "Summer"    0
13  2013-01-02  76065  FALSE       0

I've used this code:

ggplot(data=test, aes(x=Persnr, y=AmountHolidays, fill=Holiday)) +
  geom_bar(stat="identity")

What I want to see is a graph of the total amount of holidays of each Persnr visualised in a stacked bar chart sorted by the holiday (e.g. christmas, summer, etc).

This is what I got by using the code: test

I got no values whatsoever. I'd like to have an overview of the total amount of holidays of each person sorted by holiday.

Some info of my data frame.

str(df.data)

'data.frame':   490 obs. of  6 variables:
 $ Date          : chr  "2011-01-01" "2011-01-01" "2011-01-01" "2011-01-01" ...
 $ Persnr        : num  55312 55316 55325 76065 71928 ...
 $ AmountHolidays: num  0 3 0 0 1 0.5 0 0.5 2 0 ...
 $ Holiday       : chr  "FALSE" "FALSE" "FALSE" "FALSE" ...

All help is appreciated. Thanks!

1 Answer 1

4

By default, Persnr is treated like a numeric value, so x-axis is continuous with a lot of empty spaces, so the width of each existing bar is lass than 1 pixel. What you probably want is

ggplot(data=dd, aes(x=factor(Persnr), y=AmountHolidays, fill=Holiday)) + 
  geom_bar(stat="identity")

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.