[R] Differentiate values in a plot by colour or symbol

Tobias Christoph s3tochri at uni-bayreuth.de
Tue May 30 20:23:22 CEST 2017


Ahh, okay.

I think now I understand what you exactly mean. But the plot is stil not 
working /differentiate the dots by color. I used the following formula.

"plot(data$stations, data$revenue, xlab="stations", ylab="revenue", col 
= findInterval(data$year, c(2005, 2010, 2015))"

I think the problem is stil related to the term "col = 
findInterval(data$year, c(2005, 2010, 2015))" and its notation.

Just to make sure: "data" is the name of the data-table imported in R. 
"year" is the lable of the column where the years are listed in the 
data-table?

Cheers



Am 30.05.2017 um 19:57 schrieb Ismail SEZEN:
>
>> On 30 May 2017, at 20:48, Tobias Christoph <s3tochri at uni-bayreuth.de 
>> <mailto:s3tochri at uni-bayreuth.de>> wrote:
>>
>> Hi Ismael,
>>
>> thanks for your quick reply.
>>
>> I was now able to esmitate two intervals with the 
>> "findInterval"-Function.
>>
>>    x
>>   [1,] 2005 1
>>   [2,] 2006 1
>>   [3,] 2007 1
>>   [4,] 2008 1
>>   [5,] 2009 1
>>   [6,] 2010 1
>>   [7,] 2011 2
>>   [8,] 2012 2
>>   [9,] 2013 2
>> [10,] 2014 2
>> [11,] 2015 2
>> [12,] 2016 2
>>
>> But I was not able to connect the intervals with the plot-function. I 
>> used the following formular.
>>
>> "plot(data$stations, data$revenue, xlab="stations", ylab="revenue", 
>> col(findInterval())"
>>
> In fact I should say “feed _col_ or _pch_ argument with the result of 
> findInterval” as below:
>
> plot(data$stations, data$revenue, xlab="stations", ylab="revenue", col 
> = findInterval(x$year, c(2005, 2010, 2015))
>
> Please note that If you have many (20-30) intervals, colour handling 
> will be more complex. But I assume you have maximum 5-10 intervals. 
> So, the piece of code above will work for you.
>
>> How can I proceed and get the plot-funktion running?
>>
>> Maybe it is not running because the years as single numbers are 
>> already contained in my data-frame?
>>
>> Cheers,
>>
>> Toby
>>
>>
>>
>> Am 30.05.2017 um 18:26 schrieb Ismail SEZEN:
>>>> On 30 May 2017, at 19:02, Tobias Christoph<s3tochri at uni-bayreuth.de>  wrote:
>>>>
>>>> Hey Guys,
>>>>
>>>> I just try to differentiate certain values in my plot by colour or symbol.
>>>>
>>>> I have panel data with three dimensions (number of stations, revenue,
>>>> years). To integrate the third dimension (years) in the plot, I want to
>>>> differentiate the values(number of stations, revenue) by a certain range
>>>> of years.
>>>>
>>>> e.g.: 2005-2010: red coloured dots, 2011-2016, blue coloured dots
>>>>
>>>> For the normal plot I used the following formula:
>>>>
>>>> *plot(data$stations, data$revenue, xlab="stations", ylab="revenue")*
>>>>
>>>> I only found a way to mark every single year. So hopefully you can help?
>>>>
>>>> Cheers,
>>>>
>>>> Toby
>>>>
>>> See ?findInterval. Especially, first 3 lines in _Examples_ section. Use result of findInterval as argument to _col_ or _pch_ in plot function.
>>>
>>>
>>
>


	[[alternative HTML version deleted]]



More information about the R-help mailing list