[R] error while creating a simple graph

Rainer Krug rainer_krug at icloud.com
Tue Jun 20 16:04:03 CEST 2017


> On 20 Jun 2017, at 07:18, Yogesh Gupta <yogesh2cute at gmail.com> wrote:
> 
> Dear All,
> 
> I am learning R so it's a very simple problem but I do not understand while
> I am not able to generate a graph from two vectors.
> 
> when I type this code, it generates a very nice graph.
> 
> pdf("mygraph.pdf")
>> attach(mtcars)
>> plot(wt,mpg)
>> abline(lm(mpg~wt))
>> title("Regreesion of mpg")
>> detach(mtcars)
>> dev.off()
> 
> But I am trying to create a graph from this code, it generates a pdf with
> nothing.
> 
> 
>> dev.new()
>> pdf("test.pdf")
>> x <- c(1,3,6,9,12)
>> y <- c(1.5,2,7,8,15)
>> plot(x,y)
> 

As in your first example, you have to with of the device by using dev.off(). Only then is the pdf completed.

Rainer
> 
> Thanks
> Yogesh
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list