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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:54:37+00:00 2026-06-16T01:54:37+00:00

I am writing R scripts which play just a small role in a chain

  • 0

I am writing R scripts which play just a small role in a chain of commands I am executing from a terminal. Basically, I do much of my data manipulation in a Python script and then pipe the output to my R script for plotting. So, from the terminal I execute commands which look something like $python whatever.py | R CMD BATCH do_some_plotting.R. This workflow has been working well for me so far, though I have now reached a point where I want to overlay multiple histograms on the same plot, inspired by this answer to another user’s question on Stackoverflow.

Inside my R script, my plotting code looks like this:

pdf("my_output.pdf")
plot(hist(d$original,breaks="FD",prob=TRUE), col=rgb(0,0,1,1/4),xlim=c(0,4000),main="original - This plot is in beta")
plot(hist(d$minus_thirty_minutes,breaks="FD",prob=TRUE), col=rgb(1,0,0,1/4),add=T,xlim=c(0,4000),main="minus_thirty_minutes - This plot is in beta")

Notably, I am using add=T, which is presumably meant to specify that the second plot should be overlaid on top of the first. When my script has finished, the result I am getting is not two histograms overlaid on top of each other, but rather a 3-page PDF whose 3 individual plots contain the titles:

i) Histogram of d$original
ii) original – This plot is in beta
iii) Histogram of d$minus_thirty_minutes

So there’s two points here I’m looking to clarify. Firstly, even if the plots weren’t overlaid, I would expect just a 2-page PDF, not a 3-page PDF. Can someone explain why I am getting a 3-page PDF? Secondly, is there a correction I can make here somewhere to get just the two histograms plotted, and both of them on the same plot (i.e. 1-page PDF)?

The other Stackoverflow question/answer I linked to in the first paragraph did mention that alpha-blending isn’t supported on all devices, and so I’m curious whether this has anything to do with it. Either way, it would be good to know if there is a R-based solution to my problem or whether I’m going to have to pipe my data into a different language/plotting engine.

  • 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-16T01:54:37+00:00Added an answer on June 16, 2026 at 1:54 am

    Your problem is that hist plots by default, returning invisibly a histogram object that can be plotted. So calling plot(hist(..)) plots the histogram twice (two pages in your pdf), using add=T in the second call means that a third, but not fourth plot is created. You can set plot = FALSE, or not wrap the calls to hist within plot().

    To get this to work as a single page pdf (using the example from How to plot two histograms together in R?

    set.seed(42)
    p1 <- hist(rnorm(500,4), plot=  FALSE)                     # centered at 4
    p2 <- hist(rnorm(500,6), plot = FALSE)    
                                                 # centered at 6
    pdf('foo.pdf')
    plot( p1, col=rgb(0,0,1,1/4), xlim=c(0,10))  # first histogram
    plot( p2, col=rgb(1,0,0,1/4), xlim=c(0,10), add=T)
    
    dev.off()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running several scripts which are writing and reading from the same CSV file
I've seen some shell scripts in which they pass a file by writing the
I'm writing some PowerShell scripts to work with our source control software (which is
I am currently writing a script which parses the ServiceTage, Computername and Username from
I'm writing a script which is to be executed hourly. It basically works as:
I am writing python script which gets links from website. But when I tried
I'm writing a backup script which Copies the data to backup disk. Flushes the
I'm writing a bash script in which I read single characters from the input.
I wanted to write a small script which displays a image or play a
I'm not extremely familiar with IBM MQSeries, but I am writing c# scripts which

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.