[R] Changing the label name in the plot

Subhamitra Patra @ubh@m|tr@@p@tr@ @end|ng |rom gm@||@com
Tue Jun 11 16:27:56 CEST 2019


Hello Sir,

No, two data columns don't have the same names. 1st columns contain the
data from the developed markets, whereas the 2nd columns from the emerging
markets, but I provided the same header name as name, and name.1.

But, whatever clustering method I got from the R bloggers that they are
using the same name column for the multi-data column. So, easily they are
getting plotted along with the clustered values.

But, in my case, 2 data columns have different name columns, so while
plotting, one is suppressing upon others, and thus making the plot unclear.
I tried to do clustering separately for DMs, and EMs, as they have
different name columns. But, somehow it is not working.

Ok, considering your suggestion, I will check by changing the header name
for both data column and will let you know the result.

Thank you.



[image: Mailtrack]
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
Sender
notified by
Mailtrack
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&>
06/11/19,
7:52:59 PM

On Tue, Jun 11, 2019 at 7:44 PM Bert Gunter <bgunter.4567 using gmail.com> wrote:

> There appear to be two columns with the same name. Surely this will cause
> problems.
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Tue, Jun 11, 2019 at 3:19 AM PIKAL Petr <petr.pikal using precheza.cz> wrote:
>
>> Hi
>>
>> Ts should be numeric matrix if I read the help page correctly. However I
>> get different error message
>>
>> > k2 <- kmeans(ts, centers = 2, nstart = 25)
>> Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)
>> In addition: Warning message:
>> In storage.mode(x) <- "double" : NAs introduced by coercion
>>
>> So there must be another issue with your data.
>>
>> Cheers
>> Petr
>>
>> -----Original Message-----
>> From: R-help <r-help-bounces using r-project.org> On Behalf Of Subhamitra Patra
>> Sent: Tuesday, June 11, 2019 10:49 AM
>> To: Jim Lemon <drjimlemon using gmail.com>; r-help mailing list <
>> r-help using r-project.org>
>> Subject: Re: [R] Changing the label name in the plot
>>
>> Hello Sir,
>>
>> Thank you very much for your help. I tried your suggestion but got some
>> error, which I am pasting below.
>>
>>
>> Error: unexpected symbol in:
>> "
>>               header"
>> > library(cluster)
>> Warning message:
>> package ‘cluster’ was built under R version 3.5.3
>> > k2 <- kmeans(ts, centers = 2, nstart = 25)
>> Error in as.vector(x, mode) :
>>   cannot coerce type 'closure' to vector of type 'any'
>> >                plot(ts[c(2,4)],col=k2$cluster,type="n")
>> Error in ts[c(2, 4)] : object of type 'closure' is not subsettable
>> >                text(ts[c(2,4)],ts$Name.1,col=k2$cluster)
>> Error in ts[c(2, 4)] : object of type 'closure' is not subsettable
>>
>>
>> Please help me.
>>
>> Thank you.
>>
>> [image: Mailtrack]
>> <
>> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
>> >
>> Sender
>> notified by
>> Mailtrack
>> <
>> https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=signaturevirality5&
>> >
>> 06/11/19,
>> 3:17:19 PM
>>
>> On Tue, Jun 11, 2019 at 3:00 PM Jim Lemon <drjimlemon using gmail.com> wrote:
>>
>> > Hi Subhamitra,
>> > I don't have the factoextra package, but this may give you what you
>> want:
>> >
>> > ts<-read.table(text="Name DMs Name EMs A 2.071 a 2.038 B 2.0548 b
>> > 2.017 C 2.0544 c 2.007 D 2.047 d 1.963 E 2.033 f 1.947 F 2.0327 g
>> > 1.942 G 2.0321 h 1.932 H 2.031 i 1.924 I 2.0293 j 1.913 J 2.0291 k
>> > 1.906 K 2.027 l 1.892 L 2.022 m 1.877 M 1.9934 n 1.869 N 1.993 o 1.849
>> > O 1.989 p 1.848 P 1.988 q 1.836 Q 1.987 r 1.835 R 1.9849 s 1.819 S
>> > 1.9842 t 1.798 T 1.981 u 1.771 U 1.978 v 1.762 V 1.968 w 1.717 W 1.96
>> > x 1.707 X 1.958 y 1.688 Y 1.955 z 1.683 Z 1.953 aa 1.671 AA 1.952 ab
>> > 1.664 AB 1.95 ac 1.646 AC 1.948 ad 1.633 AD 1.945 ae 1.624 AE 1.937 af
>> > 1.621 AF 1.913 ag 1.584 AG 1.901 ah 1.487 AH 1.871 ai 1.482 AI 1.801
>> > aj 1.23 AJ 1.761 ak 1.129 AK 1.751 al 1.168 AL 1.699 am 0.941 AM 1.687
>> > an 0.591 AN 1.668 ao 0.387 AO 1.633 ap 0.16 AP 1.56 aq 0.0002",
>> > header=TRUE,stringsAsFactors=FALSE)
>> > library(cluster)
>> > k2 <- kmeans(ts, centers = 2, nstart = 25)
>> > plot(ts[c(2,4)],col=k2$cluster,type="n")
>> > text(ts[c(2,4)],ts$Name.1,col=k2$cluster)
>> >
>> > Jim
>> >
>> > On Tue, Jun 11, 2019 at 2:44 PM Subhamitra Patra
>> > <subhamitra.patra using gmail.com> wrote:
>> > >
>> > > Dear R-users,
>> > >
>> > > I am doing cluster analysis, but when I am plotting the results, the
>> no.
>> > of
>> > > observation is coming as the level. Hence, I have a different level
>> > > name for each observation differently for each column. I have 2
>> > > columns,
>> > namely
>> > > DMs, and EMs, which will be clustered, but I am unable to label each
>> > > dot
>> > in
>> > > the cluster as per their different name. In other words, the dots in
>> > > the cluster are being labeled as per their number of observation
>> > > which I want to rename as per their different name in the data. But,
>> > > sometimes in
>> > code,
>> > > both the columns indicating the cluster names are not supporting due
>> > > to their non-numerical texts.
>> > >
>> > > Hence, my query is how to rename or change the label of each dot in
>> > > a cluster. Here is my code.
>> > >
>> > > library(tidyverse)
>> > > library(cluster)
>> > > library(factoextra)
>> > > k2 <- kmeans(ts, centers = 2, nstart = 25) fviz_cluster(k2, data =
>> > > ts)
>> > >
>> > > Here, I have 2 columns i.e. DMs, and EMs with their different label
>> > > name (i.e. the different name for different observation differently
>> > > for 2 columns), and want to plot such label name in the cluster
>> > > graph rather
>> > than
>> > > the no. of observation.
>> > >
>> > > For your convenience, I am attaching my data.
>> > >
>> > > Please find the attached data, and kindly help me in this regard.
>> > >
>> > > Thank you.
>> > >
>> > >
>> > >
>> > > --
>> > > *Best Regards,*
>> > > *Subhamitra Patra*
>> > > *Phd. Research Scholar*
>> > > *Department of Humanities and Social Sciences* *Indian Institute of
>> > > Technology, Kharagpur*
>> > > *INDIA*
>> > >
>> > > [image: Mailtrack]
>> > > <
>> > https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaig
>> > n=signaturevirality5&
>> > >
>> > > Sender
>> > > notified by
>> > > Mailtrack
>> > > <
>> > https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaig
>> > n=signaturevirality5&
>> > >
>> > > 06/11/19,
>> > > 9:54:45 AM
>> > > ______________________________________________
>> > > R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > > https://stat.ethz.ch/mailman/listinfo/r-help
>> > > PLEASE do read the posting guide
>> > http://www.R-project.org/posting-guide.html
>> > > and provide commented, minimal, self-contained, reproducible code.
>> >
>>
>>
>> --
>> *Best Regards,*
>> *Subhamitra Patra*
>> *Phd. Research Scholar*
>> *Department of Humanities and Social Sciences* *Indian Institute of
>> Technology, Kharagpur*
>> *INDIA*
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>> Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních
>> partnerů PRECHEZA a.s. jsou zveřejněny na:
>> https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information
>> about processing and protection of business partner’s personal data are
>> available on website:
>> https://www.precheza.cz/en/personal-data-protection-principles/
>> Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou
>> důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení
>> odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any
>> documents attached to it may be confidential and are subject to the legally
>> binding disclaimer: https://www.precheza.cz/en/01-disclaimer/
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

-- 
*Best Regards,*
*Subhamitra Patra*
*Phd. Research Scholar*
*Department of Humanities and Social Sciences*
*Indian Institute of Technology, Kharagpur*
*INDIA*

	[[alternative HTML version deleted]]



More information about the R-help mailing list