I want to make a color-coded Histogram and ran into a problem.
I use ggplot on R 3.1.1
The initial attempt seen below, worked just fine as long as the indicators
were numerical. When changing the indicators
to strings to make it easier to understand the graph, the order in which the bars are is scrambled.
ggplot(df_2,aes(hard_failures,fill=indicator)) + geom_histogram()
The next step was to add stat="identity"
ggplot(df_2,aes(hard_failures,fill=indicator)) + geom_histogram(stat="identity")
Now I get the following error message, which I do not know how to fix.
Error in exists(name, envir = env, mode = mode) : argument "env" is missing, with no default
Does someone know how to fix the error message?
Alternatively,does someone know how to change what is written next to the colors on the side, so I can keep the indicators
numerical and simply edit the graph afterwards?
Sorry for the way I put the data in. I don't know how I am supposed to put the data in.
hard_failures indicator
36 2
3 1
46 2
36 2
54 2
3 1
6 1
47 2
hard_failures indicator
36 "Time-Rule"
3 "Voltage-Rule"
46 "Time-Rule"
36 "Time-Rule"
54 "Time-Rule"
3 "Voltage-Rule"
6 Voltage-Rule
47 Time-Rule
Edit:
The output of dput(head(yourData, 10))
for when the data is numeric.
structure(list(hard_failures = c(36, 3, 46, 36, 54, 3, 6, 47,
55, 2), indicator = structure(c(2L, 1L, 2L, 2L, 2L, 1L, 1L, 2L,
2L, 1L), .Label = c("1", "2"), class = "factor")), .Names = c("hard_failures",
"indicator"), row.names = c(NA, 10L), class = "data.frame")`
The output of dput(head(yourData, 10))
for when the data is in strings.
structure(list(hard_failures = structure(c(21L, 14L, 32L, 21L,
41L, 14L, 43L, 33L, 42L, 8L), .Label = c("0", "1", "10", "11",
"12", "14", "19", "2", "20", "21", "23", "28", "29", "3", "30",
"31", "32", "33", "34", "35", "36", "37", "38", "39", "4", "40",
"41", "42", "43", "44", "45", "46", "47", "48", "49", "5", "50",
"51", "52", "53", "54", "55", "6", "7", "8", "9"), class = "factor"),
indicator = structure(c(1L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L,
2L), .Label = c("Time-Rule", "Voltage-Rule"), class = "factor")), .Names >= c("hard_failures",
"indicator"), row.names = c(NA, 10L), class = "data.frame")`