Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8335153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:34:49+00:00 2026-06-09T03:34:49+00:00

I have a data frame like this: Server Date Server Space 1 2010-01-30 server1

  • 0

I have a data frame like this:

Server

     Date     Server  Space
1 2010-01-30 server1       100
2 2010-02-28 Server1       400  
3 2010-03-30 Server1     300
4 2010-04-30 Server2       200
5 2010-05-30 Server2       500  
6 2010-06-30 Server2       300

based on this data frame, I use aggregate to group Harddisk usage by month and store it in a data frame called z, as below.
z

  Month   Value
1 2010-01 600
2 2010-02 700
3 2010-03 800
4 2010-04 900
5 2010-05 800
6 2010-06 900

I am trying to create a stack chart on x and put a line on the total based on z on top of the same stack chart using ggplot2.

syntax is below:

I had to do this to avoid (Error: Discrete value supplied to continuous scale)

server$Date<-as.character(server$Date)

then run this:

ggplot(server, aes(Date, Space)) +  geom_bar(aes(fill=Server), stat="identity", position="stack") + theme_bw() + scale_x_discrete(name="Date") + scale_y_continuous("Space") +  opts(axis.title.x = theme_text(face="bold", colour="#990000", size=15),axis.text.x  = theme_text(angle=90), axis.title.y = theme_text(face="bold", colour="#990000", angle=90, size=15)) + geom_smooth(data=z,aes(Month,Value,group=1), method="lm", size=2, color="darkblue") 

This works but on my xaxis, I have two sets of data, which looks very cluttered. Is it possible to hide or suppress the dates from x data frame and only show z$Month on xaxis?

I can use this:

scale_x_date(labels = date_format("%m-%Y")) 

But when I do this, xaxis is now showing 01-1970 for all data points.

*Update *
Let me ask this question in other way. I like to create a stack chart and on top of the stack, put a linear line using geom_smooth() to show where the total usage is going. I was thinking use x data frame to build the stack chart, then create another data frame for the total value and create the geom_smooth() line based on the total data frame as z. Doing it this way, puts 2 data values to the xaxis.

Rather than doing it this way, is it possible to draw geom_smooth() on the stack bar based on x data frame?

This is the dput of the data frame:

server <- structure(list(Date = structure(c(1325394000, 1325480400, 1325566800, 
1325653200, 1325739600, 1325826000, 1325912400, 1325998800, 1326085200, 
1326171600, 1326258000, 1326344400, 1326430800, 1326517200, 1326603600, 
1326690000, 1326776400, 1325394000, 1325480400, 1325566800, 1325653200, 
1325739600, 1325826000, 1325912400, 1325998800, 1326085200, 1326171600, 
1326258000, 1326344400, 1326430800, 1326517200, 1326603600, 1326690000, 
1326776400, 1325394000, 1325480400, 1325566800, 1325653200, 1325739600, 
1325826000, 1325912400, 1325998800, 1326085200, 1326171600, 1326258000, 
1326344400, 1326430800, 1326517200, 1326603600, 1326690000, 1326776400, 
1328072400, 1328158800, 1328245200, 1328331600, 1328418000, 1328504400, 
1328590800, 1328677200, 1328763600, 1328850000, 1328936400, 1329022800, 
1329109200, 1329195600, 1329282000, 1329368400, 1329454800, 1328072400, 
1328158800, 1328245200, 1328331600, 1328418000, 1328504400, 1328590800, 
1328677200, 1328763600, 1328850000, 1328936400, 1329022800, 1329109200, 
1329195600, 1329282000, 1329368400, 1329454800, 1328072400, 1328158800, 
1328245200, 1328331600, 1328418000, 1328504400, 1328590800, 1328677200, 
1328763600, 1328850000, 1328936400, 1329022800, 1329109200, 1329195600, 
1329282000, 1329368400, 1329454800, 1330578000, 1330664400, 1330750800, 
1330837200, 1330923600, 1331010000, 1331096400, 1331182800, 1331269200, 
1331355600, 1331442000, 1331524800, 1331611200, 1331697600, 1331784000, 
1331870400, 1331956800, 1330578000, 1330664400, 1330750800, 1330837200, 
1330923600, 1331010000, 1331096400, 1331182800, 1331269200, 1331355600, 
1331442000, 1331524800, 1331611200, 1331697600, 1331784000, 1331870400, 
1331956800, 1330578000, 1330664400, 1330750800, 1330837200, 1330923600, 
1331010000, 1331096400, 1331182800, 1331269200, 1331355600, 1331442000, 
1331524800, 1331611200, 1331697600, 1331784000, 1331870400, 1331956800
), class = c("POSIXct", "POSIXt"), tzone = ""), Server = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("ServerA", "ServerB", 
"ServerC"), class = "factor"), Space = c(100, 110, 110, 120, 
120, 130, 130, 140, 140, 150, 150, 160, 160, 170, 170, 180, 200, 
220, 240, 260, 280, 300, 320, 340, 360, 380, 400, 420, 440, 460, 
480, 500, 520, 540, 560, 580, 600, 620, 640, 660, 680, 700, 720, 
740, 760, 780, 800, 820, 840, 860, 880, 100, 110, 110, 120, 120, 
130, 130, 140, 140, 150, 150, 160, 160, 170, 170, 180, 200, 220, 
240, 260, 280, 300, 320, 340, 360, 380, 400, 420, 440, 460, 480, 
500, 520, 540, 560, 580, 600, 620, 640, 660, 680, 700, 720, 740, 
760, 780, 800, 820, 840, 860, 880, 550, 110, 560, 120, 570, 130, 
580, 140, 590, 150, 600, 160, 610, 170, 620, 180, 200, 550, 570, 
590, 610, 630, 650, 670, 690, 710, 730, 750, 600, 620, 640, 660, 
680, 700, 720, 740, 760, 780, 800, 820, 840, 860, 880, 900, 920, 
940, 960, 980, 1000, 1020, 1000)), .Names = c("Date", "Server", 
"Space"), row.names = c(NA, 153L), class = "data.frame")



z <- structure(list(Month = c("2012-01", "2012-02", "2012-03"), Value = c(21140, 
21140, 32010)), .Names = c("Month", "Value"), row.names = c(NA, 
-3L), class = "data.frame")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T03:34:51+00:00Added an answer on June 9, 2026 at 3:34 am

    Since you are working with dates (and not DateTimes), you’ll find it easier if both your date columns are as.Date objects:

    server$Date <- as.Date(server$Date)
    z$Month <- as.Date(paste0(z$Month, "-01"))
    
    ggplot(server, aes(Date, Space)) +  
      geom_bar(aes(fill=Server), stat="identity", position="stack") +
      geom_point(data=z,aes(Month,Value,group=1), color="darkblue") +
      geom_line(data=z,aes(Month,Value,group=1), color="darkblue")
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data frame that looks like this: site date var dil 1
I have a data frame with gaps like this: Var1 Var2 Var3 1 NA
I have a data.frame that looks like this: > head(ff.df) .id pio caremgmt prev
I have a data.frame in R that looks like this: score rms template aln_id
I have a data frame in R that looks like this: > TimeOffset, Source,
I have a dataframe with numeric entries like this one test <- data.frame(x =
Suppose I have a dataframe like this one: df <- data.frame (id = c(a,
I have this huge data frame that has servernames, Date, CPU, memory as the
i have data frame like this : 1 2 3 4 5 1 0.1
Say I have a data frame like this: Df <- data.frame( V1 = c(1,2,3,NA,5),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.