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

  • Home
  • SEARCH
  • 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 6878065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:40:39+00:00 2026-05-27T04:40:39+00:00

Below is a plot which should contain lines of different types (solid and dashed)

  • 0

Below is a plot which should contain lines of different types (solid and dashed) according to two groups (specified by the variable “m”). As you can see, it’s close to being correct, but the lines kind of randomly connect the points instead of only connecting the points in the corresponding group.

This looks quite similar to what’s in Hadley’s book (page 50), but although I used the “group”-variable, it’s still not as expected.

## new minimal example
require(ggplot2)
require(reshape2)
require(plyr)
set.seed(1)

## parameters
m <- c("g1", "g2")
x <- c(10, 20, 50, 100)
z <- c(5, 20, 50)
N <- 1000

## lengths
lm <- length(m)
lx <- length(x)
lz <- length(z)

## build result array containing the measurements
arr <- array(rep(NA, lm*lx*lz*N), dim=c(lm, lx, lz, N),
             dimnames=list(
             m=m,
             x=x,
             z=z,
             N=1:N))
## fill with dummy data
for(i in 1:lx){
    for(j in 1:lz){
         arr[1,i,j,] <- 0+i+j+runif(N, min=-4, max=4)
    }
}
arr[2,,,] <- arr[1,,,] + 2
names(dimnames(arr)) # "m"  "x"  "z" "N"

## compute a (dummy) summary statistic
means <- apply(arr, MARGIN=1:3, FUN=mean)

## create molten data
mdf <- reshape2:::melt.array(means, formula = . ~ m + x + z, value.name="Mean")
mdf. <- mutate(mdf, xz=x*z) # add x*z
mdf.$x <- as.factor(mdf.$x) # change to factor (for grouping with different shapes)

## trial
sym <- c(1, 2, 4, 20) # plot symbols
ggplot(mdf., aes(x=xz, y=Mean, shape=x)) +
    geom_line(aes(group=x)) + geom_point() + # indicate group 1 by solid lines
    geom_line(aes(group=m), linetype=2) + # indicate group 2 by dashed lines
    scale_shape_manual(values=sym, breaks=x) +
    labs(x="x times z", y="Mean")
## => Each of the two groups specified by m should be depicted by a special line type
##    (solid for "g1", dashed for "g2"), but the lines are not correctly drawn...
##    The goal is to connect the dots of the second group by a dashed line and to
##    highlight the nodes by the same plot symbols (sym) as for the first group.
  • 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-27T04:40:40+00:00Added an answer on May 27, 2026 at 4:40 am

    As @lselzer says, try removing the first geom_line and moving the linetype argument into the aes:

    ggplot(mdf., aes(x=xz, y=Mean, shape=x)) +
        geom_point() + 
        geom_line(aes(group=m,linetype = m)) + # indicate group 2 by dashed lines
        scale_shape_manual(values=sym, breaks=x) +
        labs(x="x times z", y="Mean")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one y variable, which I am trying to plot against two related
I have two arrays which contain times. The first is the state of a
I have a plot (sample code pasted below) that I am trying to add
Below are two ways of reading in the commandline parameters. The first is the
Below is part of the XML which I am processing with PHP's XSLTProcessor :
Below are lines from the c++ programming language template<class T > T sqrt(T );
I have 6 vectors which I want to plot. How I can make each
I have a plot which has timestamps on the x-axis and some signal data
I have below a code that will plot a sphere, it's proportions are defined
I have a a stacked bar plot using ggplot for which I'm trying to

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.