Error with Histogram Code, Please Help!

rstudio
#1

Hi There,

I'm using RStudio on a PC with Windows 10, and I keep running into errors when I try and run my code to create two histograms, but when I use the same code with a different data file it works fine.

The error message is:

hist(Oligofructose ~ Placebo, las=1, nrow=2, ncol=1, cex.main=0.8, xlab="Calcium Absorption (%)")
Error: RHS may contain only factor variables.

The code that works is:
chicks = read.csv("CornChicks.csv")
attach(chicks)

library(FSA)
op <- par(oma=c(0,0,1.5,0))
hist(WtGain ~ Group, las=1, nrow=2, ncol=1, cex.main=0.8, xlab="Weight Gain (g)")
mtext("Weight Gain in Chicks on Two Diets", side=3, outer=TRUE, font=2)
par(op)

And this is the code that needs to work, but just won't:
Oligo_paired = read.csv("Oligo_paired.csv")
attach(Oligo_paired)

library(FSA)
op <- par(oma=c(0,0,1.5,0))
hist(Oligofructose ~ Placebo, las=1, nrow=2, ncol=1, cex.main=0.8, xlab="Calcium Absorption (%)")
mtext("Difference in Calcium Absorption: Placebo - Oligofructose", side=3, outer=TRUE, font=2)
par(op)

Any help is greatly appreciated, thank you in advance!

0 Likes

#2

This means that Placebo (if I'm reading it correctly) needs to be a factor. There's a quick intro here:
https://monashbioinformaticsplatform.github.io/2015-09-28-rbioinformatics-intro-r/01-supp-factors.html
and lots more detail in the chapter on factors in R for Data Science below (as well as many other places, just a couple links to get you started)

0 Likes

#3

Thank you for the response!

I have finally figured it out after a lot of heartache, but I might keep this thread open so I can have a look at the links you posted.

Thank you again! :slight_smile:

0 Likes