Error when trying to use corrplot


Hi Guys,

I want to draw a Corrplot, but I always get different errors.

I have a record on baseball and I want to analyze if the salary is dependent on the number of games, number of homers, and runs per season.

The following command I get the following error

corrplot(cor(data[c("lsalary","hrunsyr","atbatsyr")]),method = "color", 
         main= Korrelation zwischen relevanten Merkmalen,order= "AOE", 
         add.Coef.col = "chartreuse3",type= "upper",data=major_league_baseball)
Error: unknown symbol in "corrplot (cor (data [c (" salary "," hrunsyr "," atbatsyr ")]), method =" color ", main = correlation between"

many thanks for your help


Hi! Welcome to RStudio Community!

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.


If you've never heard of a reprex before, you might want to start by reading the help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "")

For pointers specific to the community site, check out the reprex FAQ, linked to below.

In addition, it looks like your code was not formatted correctly to make it easy to read for people trying to help you. Formatting code allows for people to more easily identify where issues may be occurring, and makes it easier to read, in general. I have edited you post to format the code properly.

In the future please put code that is inline (such as a function name, like mutate or filter) inside of backticks (`mutate`) and chunks of code (including error messages and code copied from the console) can be put between sets of three backticks:

example <- foo %>%
  filter(a == 1)

This process can be done automatically by highlighting your code, either inline or in a chunk, and clicking the </> button on the toolbar of the reply window!

This will help keep our community tidy and help you get the help you are looking for!

For more information, please take a look at the community's FAQ on formating code


thanks a lot for your quick help

Unfortunately, I'm not a big R professional. I have the reprex installed.

How can I create a reproducible code?

It may well be that the fomatierung does not fit, I have already tried many combinations and have arrived nicely at the end of my knowledge.

Best regards


Did you take a look at any of the links I provided in my last response?

Essentially, in order to make the reprex work, you need to define all of the data and libraries that you are needed to run your code and the code that you are running. the reprex outputs will give you the outputs of all of the commands that you run, and if you have created the reprex correctly, then the output will be the same error that you are experiencing with your code.


I also encourage you to read up on reproducible examples and the reprex package — even if you're new at this! Getting better at asking for help is one of the best investments you can make in your R skills.

However, looking at the code snippet you posted, I see one obvious thing wrong: the text for your plot title (the main parameter) is not enclosed in quotation marks. Does this work any better?

  cor(data[c("lsalary", "hrunsyr", "atbatsyr")]),
  method = "color",
  main = "Korrelation zwischen relevanten Merkmalen",
  order = "AOE",
  add.Coef.col = "chartreuse3",
  type = "upper",
  data = major_league_baseball

(By the way, I used RStudio's automatic code reformatting on this code block to make it a little easier to read. RStudio also warned me about the missing quotes on the main value with its Code Diagnostics feature, which can be really helpful for catching syntax errors!)

Note: I have not tested this code! Because this example is not reproducible, I wasn't even entirely sure which corrplot() function you are using (there is more than one function with that name across various packages). If there's a new error after fixing this small typo, then I think we will definitely need a reproducible example to get to the bottom of that.


Thank you for your quick response.

I have the link to represent, but I do not know why I should be here?

I entered the tip for the main parameter on a trial basis with the following command

corrplot (cor (data [c ("lsalary", "hrunsyr", "atbatsyr")]), method = "color", main = "correlation between relevant features", order = "AOE", add.Coef.col = "chartreuse3", type = "upper", data = major_league_baseball)

errors occur

Errors in data [c ("lsalary", "hrunsyr", "atbatsyr")]:
Object of type 'closure' is not indexable

Best regards


That’s the error you get when you haven’t actually defined an object named data (containing your data). There is a built-in R function called data() which is used for loading example data from packages. When you haven’t defined your own data object, R falls back to assuming you mean this function (“closure” is computer science jargon that in this case basically means function), and then of course an error occurs since the code makes no sense interpreted that way.

Please do take a look at the links and info @tbradley posted on making reproducible examples and formatting your code in posts here. Trying to follow those guidelines is going to be the most efficient way to get help here.