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 9246425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:29:04+00:00 2026-06-18T09:29:04+00:00

t <- structure(list(X = 1:30, Country = structure(c(3L, 1L, 3L, 1L, 3L, 1L, 3L,

  • 0
t <- structure(list(X = 1:30, Country = structure(c(3L, 1L, 3L, 1L, 
3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 2L, 2L, 
3L, 1L, 3L, 1L, 3L, 1L, 2L, 3L, 1L, 3L), .Label = c("China", 
"Germany", "USA"), class = "factor"), Industry = structure(c(3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("Agriculture", 
"IT", "Manufacturing"), class = "factor"), Date = structure(c(15393, 
15393, 15394, 15394, 15397, 15397, 15398, 15398, 15399, 15399, 
15400, 15400, 15401, 15401, 15404, 15404, 15405, 15405, 15405, 
15405, 15406, 15406, 15407, 15407, 15408, 15408, 15408, 15411, 
15411, 15412), class = "Date"), count = c(4L, 1L, 5L, 1L, 4L, 
1L, 4L, 1L, 8L, 1L, 7L, 1L, 4L, 1L, 4L, 1L, 9L, 1L, 4L, 3L, 4L, 
1L, 4L, 1L, 9L, 1L, 2L, 7L, 1L, 4L)), .Names = c("X", "Country", 
"Industry", "Date", "count"), row.names = c(NA, 30L), class = "data.frame")

I need to have yaxis scale to be proportionate to the data in that panel. When I do this:

# install.packages("ggplot2", dependencies = TRUE)
# install.packages("scales", dependencies = TRUE)
require(ggplot2)
require(scales)
p1 <- ggplot(t, aes(Date, count)) + 
  geom_bar(aes(fill=Industry), stat="identity", position="stack") + 
  geom_smooth(method="lm", se=T, size=0.5, colour="yellow") +
  xlab("Date") + ylab("Number of Input") +
  facet_grid(Industry~Country, scale="free", margins=T) + 
  theme(legend.position = 'bottom', legend.direction = 'horizontal', legend.title = element_blank(), legend.text = element_text(size=10, face = 'bold')) +theme(axis.title.x = element_text(face="bold", colour="white", size=12), axis.text.x  = element_text(angle=90, face="bold", size=10),axis.title.y = element_text(face="bold", colour="white", angle=90, size=10), axis.text.y=element_text(size=10, face="bold"),legend.text = element_text(size=10, face = 'bold'), legend.title = element_blank()) +scale_x_date(breaks = "3 month", minor_breaks = "1 week", labels=date_format("%b-%y"))+ theme(strip.text.x = element_text(size=10, face="bold", colour="navyblue"), strip.background = element_rect(colour="blue", fill="white"))+ ggtitle("Number of Monthly Breaches")+ 
  theme(plot.title=element_text(size=13, colour="white", face="bold")) + ylim(0, max(t$count))

yaxis limit is the same for all panels, I tried this

scales=free_y 

it does not seem to be working. Any idea how to tackle this issue?

  • 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-18T09:29:06+00:00Added an answer on June 18, 2026 at 9:29 am

    The answer above is good. I want just to structure your code because it looks really hard to maintain. I would not mix the plot and the theme statements.

    The plot alone :

    p1 <- ggplot(dat, aes(Date, count)) + 
      geom_bar(aes(fill=Industry), stat="identity", position="stack") + 
      geom_smooth(method="lm", se=T, size=0.5, colour="yellow") +
      facet_grid(Industry~Country, scales="free_y", margins=T) + 
      scale_x_date(breaks = "3 month", minor_breaks = "1 week", 
                 labels=date_format("%b-%y"))
    

    Then theme

    mytheme <-  theme(legend.position = 'bottom', legend.direction = 'horizontal',
            legend.title = element_blank(), 
            legend.text = element_text(size=10, face = 'bold')) +
      theme(axis.title.x = element_text(face="bold", colour="white", size=12), 
            axis.text.x  = element_text(angle=90, face="bold", size=10),
            axis.title.y = element_text(face="bold", 
                                        colour="white", 
                                        angle=90, 
                                        size=10),
            axis.text.y=element_text(size=10, face="bold"),
            legend.text = element_text(size=10, face = 'bold'), 
            legend.title = element_blank()) +
      theme(strip.text.x = element_text(size=10, 
                                        face="bold", colour="navyblue"), 
            strip.background = element_rect(colour="blue", fill="white"))+ 
      theme(plot.title=element_text(size=13, colour="white", face="bold"))
    
    
      p1 + mytheme
    

    enter image description here

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

Sidebar

Related Questions

dput(df) structure(list(Month = structure(c(15248, 15522), class = Date), Value = c(1, 3)), .Names =
> dput(head(t)) structure(list(Team = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = Union, class
Consider the following data structure: List<Person> People; class Person { List<Car> Cars; List<Hobby> Hobbies;
Say you have a simple class with some storage data structure (list, vector, queue,
dput(x) structure(list(Date = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L,
i have a time series data like this: x <- structure(list(date = structure(c(1264572000, 1266202800,
I am working on a data structure list class in python. I would like
I have a data frame is like this: dput(xx) structure(list(TimeStamp = structure(c(15705, 15706), class
df <- structure(list(ID = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
I'd like to create a dropdownlist from following structure List<KeyValuePair<long, string>> sponsori = new

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.