UserPc
and PostingsPc
cointain "," and "%" so read.csv
interprets them as strings (which it reads as factors) rather than numbers. You'll see this if you run str(myData)
. If you want to plot them, you need to convert them into numbers, which looking at your data requires replacing "," with "." and removing the "%". gsub
is a useful function for this, and it's convenient to make the whole operation its own function. Something like this:
MyData <- read.csv(file="data.csv", header=TRUE, sep=";",stringsAsFactors = FALSE)
#write a function that removes all "%" from a string converts "," to "." and returns a numeric
#divide by 100 because it's a percentage
convert <- function(stringpct){
as.numeric(gsub("%","",gsub(",",".",stringpct)))/100
}
MyData$UserPc <- convert(MyData$UserPc)
MyData$PostingsPc <- convert(MyData$PostingsPc)
attach(MyData)
plot(UserPc,PostingsPc,ylab = "Users", xlab= "Postings",type="l")