Expanding discrete variable x-axis

Hello, everyone!

I am producing a line graph that displays a participant's train of thought (individual words) before and after reading a story. The x-axis is to have each word produced with subjective ratings from an independent rater on a scale of 0 to 7 on the y-axis. The subjective ratings reflect what the rater presumes the word is related to the story read or not. A 0 indicates that the word is not directly related to the story, and a 7 is most definitely related to the story.

Each participant can produce as many words as possible within a 5-minute time limit. You will notice below that the free associate word x-axis for the participant is illegible. This is because the participant produced 299 words for the pre-story condition. The post-story has 254 words, with the overall number of observations at 553.

I write to ask for guidance on how to expand the x-axis as the words are considered discrete variables since they are ordered from the first word produced to the second, third, etc. Eventually, I plan to stack 5 separate line graphs into one line graph to show the differences between 5 different raters' ratings for the same participant's free associate word chain. I also plan to showcase the differences pre and post-story.

The data frame pA_CF_pre code originates from these lines below of the original particip_a data frame. The particip_a data frame is a larger data frame with all raters.

pA <- particip_a[c(7:11)] #selecting only the columns of interest (word, phase, order)
pA[pA == "1 (not at all)"] <- "1"
pA[pA == "7 (very much)"] <- "7"
pA <- as.data.frame(sapply(pA, as.numeric))
pA$word <- particip_a$word
pA$phase <- particip_a$phase
pA$order <- particip_a$order
pA <- pivot_longer(pA,cols=1:5,names_to="raters", values_to="ratings")
pA <- as.data.frame(pA)

My code to produce the line graph is this:
pA_CF_pre <- subset(pA, raters == "CF" &phase == "pre-story" & ratings)
pA_CF_plot_pre <- ggplot(pA_CF_pre, aes(x=as.factor(word), y=ratings))+geom_line(group=1)+
theme(axis.text.x = element_text(angle=90, hjust=0.5, vjust=0.5))+
xlab("free associate word")+
ggtitle("Participant A free associates (pre-story) and rater1 ratings")
pA_CF_plot_pre+scale_x_discrete(limits=pA_CF_plot_pre$word)

My plot currently looks like this:

Any help is welcome and much appreciated. Thank you so much!

Hi @cmariecan, is better help you if put a reproducible example of data.

https://forum.posit.co/t/faq-draft-use-the-reprex-package-to-prepare-your-reproducible-example-for-posting/47264

Paste the result of dput(pA_CF_pre[ 1:30, ])

Try with this lines:

pA_CF_pre$word   <-  as.factor(pA_CF_pre$word)

A_CF_plot_pre <- ggplot(pA_CF_pre, aes(x=reorder(word, - ratings) y=ratings))+geom_line(group=1)+
theme(axis.text.x = element_text(angle=90, hjust=0.5, vjust=0.5))+
xlab("free associate word")+
ggtitle("Participant A free associates (pre-story) and rater1 ratings") 

pA_CF_plot_pre+scale_x_discrete(limits=pA_CF_plot_pre$word)

Thank you for your feedback, @M_AcostaCH! My apologies for not doing so the first time.

The result of dput(pA_CF_pre[ 1:30, ]) is:

structure(list(word = structure(c(197L, 86L, 62L, 70L, 125L,
128L, 62L, 63L, 11L, 168L, 19L, 6L, 9L, 106L, 72L, 67L, 68L,
66L, 6L, 6L, 85L, 146L, 164L, 12L, 72L, 6L, 86L, 80L, 156L, 124L
), .Label = c("", "arm", "away", "backyard", "bathroom", "bed", "bedroom", "black", "blanket", "blankets", "blue", "breath", "breathe", "breathing", "brown", "building", "bus stop", "cafeterias", "camera", "car", "cars", "cat", "class", "classrooms", "cleaning", "cleanliness", "clinic", "closet", "clothing", "college", "comfortable", "construction", "crawl", "cry", "curtain", "dance", "diet", "disability", "doctor", "dog", "drink", "educate", "educating", "education", "empty", "everywhere", "exercising", "exhale", "facts", "fiction", "fight", "fire", "firepit", "fish", "floor", "flooring", "food", "fridge", "friends", "garden", "glance", "grabbing", "grasping", "grass", "green", "guys", "hand", "headphones", "heat", "holding", "home", "hospital", "hot", "hungry", "inhale", "inside", "itch", "jeans", "jump", "jumping", "kitchen", "labor", "laugh", "lawn", "lay", "laying", "learning", "leash", "left", "leg", "library", "living room", "look", "lost", "loud", "medication", "memorizing", "mirror", "missed", "missing", "mouth", "move", "mushrooms", "neighbors", "new", "nurse", "old", "orange", "orbit???", "organizing", "oven", "overwhelming", "pacing", "pads", "painting", "pantry", "paving", "pedestrians", "people", "pillow", "pillows", "pills", "planning", "polo?", "pushing", "quiet", "raccoons", "reaching", "red", "relax", "right", "round", "run", "running", "scholarship", "school", "seizure", "shirt", "shooting", "shout", "shouting", "shower", "silent", "sink", "situating", "skirball", "slow",
"smell", "smile", "socks", "sore", "sorting", "speak", "speaking",
"squirrels", "standing", "stare", "street", "streetcar", "streets",
"stretch", "students", "studying", "swallow", "sweater", "swim",
"switch", "table", "talk", "talking", "tall", "taught", "tired",
"towards", "towel", "traffic", "traveled", "tray", "trees", "truck",
"trucks", "trying", "twitch", "university", "unsaid", "unsure",
"van", "vans", "vegetables", "vehicle", "vehicles", "violence",
"vocabulary", "walk", "walking", "whisper", "whispering", "white",
"wine", "wood", "work", "workers", "working", "writing", "yell",
"yellow"), class = "factor"), phase = c("pre-story", "pre-story",
"pre-story", "pre-story", "pre-story", "pre-story", "pre-story",
"pre-story", "pre-story", "pre-story", "pre-story", "pre-story",
"pre-story", "pre-story", "pre-story", "pre-story", "pre-story",
"pre-story", "pre-story", "pre-story", "pre-story", "pre-story",
"pre-story", "pre-story", "pre-story", "pre-story", "pre-story",
"pre-story", "pre-story", "pre-story"), order = c(291L, 292L,
293L, 294L, 295L, 296L, 297L, 298L, 299L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L,
39L, 40L, 21L), raters = c("CF", "CF", "CF", "CF", "CF", "CF",
"CF", "CF", "CF", "CF", "CF", "CF", "CF", "CF", "CF", "CF", "CF",
"CF", "CF", "CF", "CF", "CF", "CF", "CF", "CF", "CF", "CF", "CF",
"CF", "CF"), ratings = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 2,
1, 1, 1, 1, 1, 3, 2, 2, 2, 1, 2, 3, 1, 2, 2, 1, 2, 1)), row.names = c(1L,
6L, 11L, 16L, 21L, 26L, 31L, 36L, 41L, 196L, 201L, 206L, 211L,
216L, 221L, 226L, 231L, 236L, 241L, 246L, 251L, 256L, 261L, 266L,
271L, 276L, 281L, 286L, 291L, 296L), class = "data.frame")

The plot produced with your above code is not exactly what I am looking for. Thank you for your suggestion!

Here is a reprex example of my initial inquiry for the line graph. I attached a link here for a CSV file for the free associate words for my working condition.

library(plyr)
library(Hmisc)
library(ggcorrplot)
library(psych)
library(tidyverse)
library(ggplot2)
library(ggthemes)
library(cowplot)
library(gridExtra)
library(patchwork)

#load csv file for list of free associates
free_associates <- read.csv("[insert csv file]/sample_word.csv")
head(free_associates)

#input order, phase, and raters columns for pre-story condition
order <- c(291:299,1:10,31:40,21:30,111:120,231:240,81:90,11:20,101:110,181:190,121:130,281:290,261:280,51:60,221:230,251:260,161:170,191:210,91:100,141:150,241:250,41:50,211:220,131:140,61:70,171:180,151:160,71:80)
phase <- rep(c("pre-story"),299)
raters <- rep(c("CF"),299)
participant_A <- data.frame(free_associates,phase,raters,order)

#convert CF chr vectors to numeric
participant_A$CF[participant_A$CF == "1 (not at all)"] <- "1"
participant_A$CF[participant_A$CF == "7 (very much)"] <- "7"
participant_A$CF <- as.numeric(sapply(participant_A$CF, as.numeric))
colnames(participant_A)[2] = "rating" #rename CF to ratings

#participant_A$word <- as.factor(participant_A$word) -- not necessary?
free_associates_pre <- ggplot(participant_A, aes(x=as.factor(word), y=rating))+geom_line(group=1)+
theme(axis.text.x = element_text(angle=90, hjust=0.5))+
xlab("free associate word")+
ggtitle("Participant A free associates and rater1 ratings")
free_associates_pre

Looking forward to any further suggestions! Thank you so much.

Kind regards,

1 Like

Maybe you could make groups in x axis.

What plot you want, you could draw?

Hello @M_AcostaCH, thank you so much for your continued support!

The plot I was looking for was similar to the above I posted; the x-axis extended to show all of the words. It turns out the solution was simpler than I expected! Using the export to PDF process, I increased the width of the dimensions (e.g., 40 inches). Here's a link to view the desired output (I cannot embed the photo in this post, I apologize!).

Thank you so much for your help! Your suggestion to make groups is also possible. It is something I will consider for the next steps in my analyses. Thank you again!

Kind regards,

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.