开发者

R: Variable Titles for Plotting

开发者 https://www.devze.com 2023-02-23 07:16 出处:网络
I\'m trying to write a function that plots a set of data using the basic plot c开发者_如何学Command. It looks something like the following.

I'm trying to write a function that plots a set of data using the basic plot c开发者_如何学Command. It looks something like the following.

myfunction = function(input.data,title.str) {
    # commands to plot input.data using plot()
    title(main=title.str)
}

myfunction(object1,'show this title')

Basically I'm trying to pass a string as an argument and use it as the title of my plot. So far all the plotting works great and the problem is that I'm getting the following error.

Error in myfunction(object1,"show this title") : unused argument(s) ("show this title")


We don't have object1 but this works for me:

myfunction = function(input.data, title.str) {
    plot(input.data)
    title(main = title.str)
}

object1 <- data.frame(x = runif(10), y = runif(10))
myfunction(object1, "foo")


I suspect the version of myfunction that gives you that error is not the same as the one that you posted. The posted code works as expected for me.

You can check this by entering myfunction on the console (without brackets) and examining the function body that is printed.

0

精彩评论

暂无评论...
验证码 换一张
取 消