0

So I have a large data-frame with usage for a mass subscribers, containing columns sub_type, minutes, SMS. Minutes and SMS are actual usage while sub_type is identifier for subscription, i.e. say we have four subscriptions, 1, 2, 3 and 4. How would i create a plot(minutes,sms) for each subscription.

> allsubs
> plot(allsubs$minutes, allsubs$sms) 

this will plot all, regardless of subscription type. So i have solved this by making 4 diffrent dataframes, making 4 queries to database via R. There must be a easier way, that i havent stumbled upon yet. Please let me know if anyone has a tip/link on how to solve this.

Kind regards,

1 Answer 1

1

You can use the formula interface to plot. It's pretty much the same as you'd use for a modelling function, assuming you've used one of them (like lm, glm, rpart etc).

plot(sms ~ minutes, data=allsubs, subset=sub_type == 1)
plot(sms ~ minutes, data=allsubs, subset=sub_type == 2)
plot(sms ~ minutes, data=allsubs, subset=sub_type == 3)
plot(sms ~ minutes, data=allsubs, subset=sub_type == 4)

Alternatively, you can use subset and with:

with(subset(allsubs, sub_type == 1), plot(minutes, sms))
with(subset(allsubs, sub_type == 2), plot(minutes, sms))
with(subset(allsubs, sub_type == 3), plot(minutes, sms))
with(subset(allsubs, sub_type == 4), plot(minutes, sms))
Sign up to request clarification or add additional context in comments.

2 Comments

Do i need any package to make use of this functionality? TRPL_ID MINS SMS 1 15 2 0 2 13 267 54 3 28 765 181 4 13 106 49 5 13 98 61 > plot(MINS ~ SMS, data=allsubs, TRPL_ID == 15) Error in plot.xy(xy, type, ...) : invalid plot type
I forgot to add the subset= bit, which was the crucial part of the function call. Oops! Now fixed up.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.