+ Reply to Thread
Results 1 to 3 of 3

Thread: cannot make R leave enough room for labels in silhouette plot ('cluster' package)

  1. #1
    TS Contributor
    Points: 41,667, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Downloads
    gianmarco's Avatar
    Location
    Italy
    Posts
    1,381
    Thanks
    237
    Thanked 305 Times in 229 Posts

    cannot make R leave enough room for labels in silhouette plot ('cluster' package)




    Dear All,
    I have problems making R plot the objects' labels in the 'silhouette' plot (out from the 'cluster' package).

    See the attached image.
    As you can see, the labels showing up in the left-hand side of the chart are truncated, i.e. there is not enough room to show them entirely. I went through the help documentation, but I couldn't find a viable solution.

    Do you think it is possible to leave enough room to the left of the chart to be able to display long labels?

    The following is the code for a sample dataset, and to get the attached chart. As for the second code, I have put some #annotations to explain what's going on.


    Thank you.
    Best

    data:
    Code: 
    mydata <- structure(c(0.47812386930075, 0.127251275299247, 0.0825022807431319, 
    -0.390445104325078, -0.0319105644397104, 0.0764012513828784, 
    0.17989154684742, 0.0376443260581566, -0.327365399920222, 0.315552204192887, 
    -0.117494744401698, 0.0127663287534032, -0.178694714940958, 0.124638408742502, 
    0.106751129148983, 0.0722788856574681, 0.173388026639424, 0.0498222975683006, 
    0.139289827320685, -0.292159660786714, 0.302569367939057, -0.454996212422005, 
    0.0733533758225443, 0.102283081186412, 0.0269966034008835, -0.291712006383772, 
    -0.10965626974681, -0.0385013609564718, 0.0141619660722275, -0.0613162683720088, 
    0.390864464926791, 0.032537394707918, -0.0981147624789522, 0.0727104299821822, 
    0.0240118483102508, -0.0877489418588905, -0.15171595339673, 0.0423707720674034, 
    0.0645146710970157, 0.108688258121981, 0.107329599470356, -0.0414354064004436, 
    -0.129054801985255, 0.107189500792259, -0.17568816523869, 0.107565034778417, 
    -0.0966435931474396, 0.0327278817962036, 0.019299439398085, -0.018178824214317, 
    -0.0349129066691172, 0.0969316887880894, -0.0443427503497396, 
    0.0694497769074093, 0.033032962969166, -0.0568557867350238, -0.0633999394784391, 
    -0.0317823708665944, 0.0288019998764433, 0.039340224635988), .Dim = c(15L, 
    4L), .Dimnames = list(c("A", "B", "C", "D", "E", "Geology", "Biochemistry", 
    "Chemistry", "Zoology", "Physics", "Engineering", "Microbiology", 
    "Botany", "Statistics", "Mathematics"), c("Dim 1", "Dim 2", "Dim 3", 
    "Dim 4")))
    code:
    Code: 
    d <- dist(mydata, method = "euclidean") # calculate the distance matrix
    
    fit <- hclust(d, method="ward.D2") # perform the hierc agglomer clustering
    
    silhouette.data <- silhouette(cutree(fit, k=3),d) # store the silhouette data for the selected cluster solution (k=3)
    
    row.names(silhouette.data) <- row.names(mydata) # give the objects' names to the rows of the object created in the above step
    
    plot(silhouette.data)
    Attached Images  
    http://cainarchaeology.weebly.com/

  2. #2
    Super Moderator
    Points: 32,527, Level: 100
    Level completed: 0%, Points required for next Level: 0
    bugman's Avatar
    Posts
    2,259
    Thanks
    291
    Thanked 326 Times in 266 Posts

    Re: cannot make R leave enough room for labels in silhouette plot ('cluster' package)

    Try adjusting the outer margins with
    par(oma=c(0,1,0,0)) and obviously adjusting it as required.
    The earth is round: P<0.05

  3. The Following User Says Thank You to bugman For This Useful Post:

    gianmarco (09-09-2017)

  4. #3
    TS Contributor
    Points: 41,667, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Downloads
    gianmarco's Avatar
    Location
    Italy
    Posts
    1,381
    Thanks
    237
    Thanked 305 Times in 229 Posts

    Re: cannot make R leave enough room for labels in silhouette plot ('cluster' package)


    Thank you Bugman,
    playing around with that and with the 'max.strlen' parameter did the trick.

    Cheers,
    Gm
    http://cainarchaeology.weebly.com/

+ Reply to Thread

           




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats