1

I am trying to create a bar and line plot with ggplot. This is my data frame called dc:

structure(list(Date = structure(c(16130, 16191, 12600, 16314, 
16375, 16436, 16495, 16556, 16617, 16679, 16740, 16801), class = "Date"), 
    Lpar_Used_Pc = c(360.02, 378.02, 396.92, 416.77, 437.61, 
    459.49, 482.46, 506.58, 531.91, 558.51, 586.43, 615.76), 
    Vios = c(64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 64L, 
    64L, 64L), Capacity = c(448L, 448L, 448L, 448L, 448L, 448L, 
    448L, 448L, 448L, 448L, 448L, 448L), Total_Used = c(424.02, 
    442.02, 460.92, 480.77, 501.61, 523.49, 546.46, 570.58, 595.91, 
    622.51, 650.43, 679.76), Percent_Used = structure(c(11L, 
    12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L), .Label = c("102.88%", 
    "107.31%", "111.97%", "116.85%", "121.98%", "127.36%", "133.02%", 
    "138.95%", "145.19%", "151.73%", "95.00%", "98.67%"), class = "factor"), 
    Login = c(489123708, 513579893.4, 539258888.1, 566221832.5, 
    594532924.1, 624259570.3, 655472548.8, 688246176.3, 722658485.1, 
    758791409.3, 796730979.8, 836567528.8)), .Names = c("Date", 
"Lpar_Used_Pc", "Vios", "Capacity", "Total_Used", "Percent_Used", 
"Login"), row.names = c(NA, -12L), class = "data.frame")

ggplot(dc)+ geom_bar(aes(Date,Total_Used,stat="identity", position="stack"),width=0.5)+geom_line(data=dc, aes(Date,Total_Used, colour="green"))+geom_line(data=dc, aes(Date, Capacity, colour="red")

I get bunch of errors. Any ideas what might be going on here? I also need the Login as label in the bar charts.

1
  • Try putting stat = 'identity' and position = 'stack' out of aes(). Commented Apr 7, 2014 at 15:44

3 Answers 3

2
ggplot(dc) + 
  geom_bar(aes(Date,Total_Used), stat="identity", width=0.5) +
  geom_line(data=dc, aes(Date,Total_Used, colour="green")) +
  geom_line(data=dc, aes(Date, Capacity, colour="red"))
Sign up to request clarification or add additional context in comments.

Comments

1

you have everything pretty much correct, just mixed up in terms of what goes in and out of the aes

ggplot(dc, aes(Date,Total_Used)) +  
    geom_bar(stat="identity", position="stack",width=0.5) + 
    geom_line(colour="green") + 
    geom_line(aes(y=Capacity), colour="red")

1 Comment

@Ricordo Saporta, how would I put the Login as label inside the bar charts?
1

Try

ggplot(dc) + 
geom_bar(aes(Date,Total_Used),stat="identity", position="stack") + 
geom_line(data=dc, aes(Date,Total_Used), colour="green") + 
geom_line(aes(Date, Capacity), colour="red")

2 Comments

I tried this. Even though there is no 2004 in my Date value, I get from 2014 through 2016. No idea what's happening here?
Yes you have 2004-07-01. Try subset(dc, Date == "2004-07-01")

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.