Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6912341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:04:47+00:00 2026-05-27T09:04:47+00:00

In the plot generated by ggplot, each label along the x-axis is a string,

  • 0

In the plot generated by ggplot, each label along the x-axis is a string, i.e., “the product in 1990”. However, the generated plot there is a period in between each word. In other words, the above string is shown as “the.product.in.1990”

How can I ensure the above “.” is not added?

The following code is what I used to add string for each point along the x-axis

last_plot()+scale_x_discrete(limits=ddata$labels$text)

Sample code:

library(ggdendro)
x <- read.csv("test.csv",header=TRUE) 
d <- as.dist(x,diag=FALSE,upper=FALSE) 
hc <- hclust(d,"ave") 
dhc <- as.dendrogram(hc) 
ddata <- dendro_data(dhc,type="rectangle")
ggplot(segment(ddata)) + geom_segment(aes(x=x0,y=y0,xend=x1,yend=y1))
last_plot() + scale_x_discrete(limits=ddata$labels$text)

each row of ddata$labels$text is a string, like “the product in 1990”.
I would like to keep the same format in the generated plot rather than “the.product.in.1990”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:04:48+00:00Added an answer on May 27, 2026 at 9:04 am

    The issue arises because you are trying to read data with column names that contain spaces.

    When you read this data with read.csv these column names are converted to syntactically valid R names. Here is an example to illustrate the issues:

    some.file <- '
        "Col heading A", "Col heading B"
        A, 1
        B, 2
        C, 3
        '
    

    Read it with the default read.csv settings:

    > x1 <- read.csv(text=some.file)
    > x1
      Col.heading.A Col.heading.B
    1             A             1
    2             B             2
    3             C             3
    4                          NA
    > names(x1)
    [1] "Col.heading.A" "Col.heading.B"
    

    To avoid this, use the argument check.names=FALSE:

    > x2 <- read.csv(text=some.file, check.names=FALSE)
    > x2
      Col heading A Col heading B
    1             A             1
    2             B             2
    3             C             3
    4                          NA
    > names(x2)
    [1] "Col heading A" "Col heading B"
    

    Now, the remaining issue is that a column name can not contain spaces. So to refer to these columns, you need to wrap your column name in backticks:

    > x2$`Col heading A`
    [1]     A     B     C      
    Levels:          A     B     C
    

    For more information, see ?read.csv and specifically the information for check.names.

    There is also some information about backticks in ?Quotes

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have generated the following plot using the R code that follows it: ggplot(lengths,
Is there a Box Plot graph, or box and whisker graph available for Reporting
Is it possible to retrieve an automatically-generated plot range in Mathematica? For example, if
My program generated triangles automatically, however the arrangement of the triangles are random on
In a ggplot2 density plot (geom_density) I have the following y-axis labels 0.000 0.005
I'm trying to generate a linear regression on a scatter plot I have generated,
The text within the plots generated by Jenkins' Plot plugin is illegible, as it
I have generated a dendrogram using ggdendro and ggplot. I have two issues regarding
I want to use a variable for the legend key label in a ggplot
Working in Python 2.7. I'm trying to plot a histogram for the numbers generated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.