0

Hi everyone i have a question about plotting in R.

I need a line plot that shows how many %users wrote which %postings.
Example would be: 25% of users wrote 80% of postings

graph

Dput output: data

data
I read the data into R from csv and attached it with the headers.
Now when i try to plot it with:

plot(UserPc,PostingsPc,ylab = "Users", xlab= "Postings",type="l")

the plot is just a black square, halp

maxey
  • 33
  • 3
  • Please provide your data in a format that's easy to get into R (e.g. a data frame or a `dput`) and also reproducible code... right now, I can't regenerate the black square plot because I don't have your data structures. If you can, I think I can help you with this... there's a special kind of chart that does something close to what you want. Thanks :) – mysteRious Mar 28 '18 at 15:22
  • link to my csv file: http://www.sharecsv.com/s/0db74612eb2d1405475225f1cab1851c/data.csv use MyData <- read.csv(file="data.csv", header=TRUE, sep=";") attach(MyData) to read it. then u can try the plot from my question – maxey Mar 28 '18 at 15:36
  • That CSV is corrupt -- what we need is for you to edit the question so that it provides all data and code and that it's reproducible. https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – mysteRious Mar 28 '18 at 15:41
  • i used dput on my data since it is so much i used a pateshare service (will link it in the question too) "https://justpaste.it/1iw0f" – maxey Mar 28 '18 at 15:49

1 Answers1

0

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")
Pdubbs
  • 1,967
  • 2
  • 11
  • 20
  • that helped alot thank you :) i did the changes with % and , to . in excel, now everything works fine thanks alot – maxey Mar 28 '18 at 17:51