I have a tibble containing 24 columns, each with 107 observations. Each column is a variable describing the bone specimen in a CT image, and all values within the columns are type "double." I would like to plot histograms of most of these 24 column variables.
The following code works for columns with variable names that do not have hyphens or slashes (i.e. PatNo, Tot.vBMD1):
ggplot(data = tibia_data) + geom_histogram(mapping = aes(x=Tot.vBMD1))
However, the same command does not work on columns with hyphens or slashes in their names:
ggplot(data = tibia_data) + geom_histogram(mapping = aes(x=Total-Area)) Error in
geom_histogram()
: ! Problem while computing aesthetics. ℹ Error occurred in the 1st layer. Caused by error: ! object 'Total' not found
It seems like the hyphen is preventing R from seeing "Total-Area" as a column name. Am I missing something simple here? Maybe about the structure of tibbles or columns within tibbles?
For non-syntactic names, surround them in backticks ``. It's good practice to avoid names like that in the first place. See make.names, which is a function that can be used to fix names, and that page also has the rules for valid names.