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

  • Home
  • SEARCH
  • 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 7093661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:28:02+00:00 2026-05-28T08:28:02+00:00

Background Hey everyone! I’m new to using R, and became interested in using it

  • 0

Background

Hey everyone!

I’m new to using R, and became interested in using it after having a team member give a tutorial of how useful it can be in an academic setting.

I am trying to write a script to automatically read my data from multiple files and then plot the resultant graphs to multiple files, so that they can be easily added to a manuscript (PowerPoint, latex, etc.)

Problem

I have found that the following code will allow me to produce a graph

p = qplot(factor(step), y, data=x, colour=c))
p = p + theme_bw()
# etc...

wrapping this around a png call will allow me to output the plot to a PNG:

png("test.png")
p = qplot(factor(step), y, data=x, colour=c))
p = p + theme_bw()
# etc...
p
dev.off()

I wanted to put the graph creation into a function so that I can create graphs and consequent seperate PNGs. So I put everything into a function:

func <- function()
{
    png("test.png")
    p = qplot(factor(step), y, data=x, colour=c))
    p = p + theme_bw()
    # etc...
    p
    dev.off()
}

If I call func() A PNG is created, but it is empty. Is there any specific reason why I can do this without the function but can’t when I’m calling it from a function?

  • 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-05-28T08:28:03+00:00Added an answer on May 28, 2026 at 8:28 am

    When using ggplot2 or lattice non-interactively (i.e. not from the command-line), you need to explicitly print() plots that you’ve constructed. So just do print(p) in the final line of your code, and all should be fine.

    This is unintuitive enough that it’s one of the most frequent of all FAQs.

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

Sidebar

Related Questions

Hey everyone, some background info: In the config file for my website, I set
Hey I am very new to PHP, I come from a design background, but
Hey everyone! I am new to blackberry programming although I do have some java
Hey, I have a python background and I'm having a couple of issues with
Hey, I have noticed that when using Internet Explorer my websites background completely disappears,
Problem Hey folks. I'm looking for some advice on python performance. Some background on
Background: At my company we are developing a bunch applications that are using the
Background I am writing and using a very simple CGI-based (Perl) content management tool
Hey everyone, this seems like it should be a simple one; I really hope
Hey. I use delayed_job for background processing. I have 8 CPU server, MySQL and

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.