unable to get plot for this data

Hi I want to make a plot with multiple lines using the data below

AXISGOLD BSLGOLDETF GOLDBEES GOLDSHARE HDFCMFGETF IDBIGOLD IPGETF IVZINGOLD KOTAKGOLD QGOLDHALF RELGOLD RELIGAREGO SBIGETS
highest 20% -0.599 -1.413 -0.442 -0.576 -0.528 -0.628 -0.467 -0.533 -0.511 -0.555 -0.549 -0.51 -0.501
2 -0.236 -0.421 -0.172 -0.214 -0.2 -0.207 -0.216 -0.185 -0.17 -0.195 -0.191 -0.196 -0.192
middle 20% 0.002 -0.069 -0.003 -0.015 -0.037 -0.025 -0.026 -0.033 0.001 0.031 -0.018 -0.023 -0.008
4 0.177 0.439 0.118 0.169 0.144 0.127 0.139 0.134 0.135 0.141 0.179 0.129 0.154
lowest 20% 0.501 1.372 0.409 0.565 0.514 0.592 0.482 0.521 0.46 0.486 0.523 0.497 0.448

Thanks in advance

We need more information and some sample data. What kind of a plot do you want? What is it supposed to show?

Have a look at FAQ: How to do a minimal reproducible example ( reprex ) for beginners

for some suggestions on how to present data and code.

1 Like

I am trying to get a plot as the pic attached. This data frame does not consist of time-variable so I am finding it difficult to plot.

Again
Have a look at FAQ: How to do a minimal reproducible example ( reprex ) for beginners

If you do not supply some usable data we really cannot do much.

Hello. I am pretty new to R and trying to learn charting better. So your request gave me something to work on. I hope I got the reprex posted right.

I copied the data example you provided and pasted it into an excel file, which I then read into R as a data frame named 'datatable'. I transformed 'datatable' from a wide to a long format. This put the columns you want to plot into one variable and the values into another. To get the line to plot right I changed the x axis to a continuous variable. Then when I plotted it out I relabeled the tick values with the text.

Hope this helps.
Amy

library(tidyverse)
library(dplyr)
library(ggplot2)
library(readxl)

#Read in the data
#I copied the example data into excel
datatable <- read_excel("C:/Users/.../Desktop/datatable.xlsx")

datatable3<-datatable%>%
  gather(key="GoldType", value="Value", -AXISGOLD)%>% #restructures from wide to long
  mutate(axis1=recode(AXISGOLD, "highest 20%"=1, "2"=2, "middle 20%"=3, "4"=4, "lowest 20%"=5))
    #changes x axis variable to continuous

datatable3%>%ggplot(aes(axis1, Value))+
  geom_line(aes(linetype=GoldType))  +
  scale_x_continuous(breaks=c(1,2,3,4,5),
                     labels=c("highest 20%", "2", "middle 20%", "4", "lowest 20%"))
                      #changes the x axis tick labels
1 Like

I am unable to rename the x-axis. I am using the

below-mentioned code

exhibit_5 <-d3%>%
gather(key="TICKER", value="Value", -AXISGOLD)%>% #restructures from wide to long
mutate(axis1=recode(AXISGOLD, "highest 20%"=1, "2"=2, "middle 20%"=3, "4"=4, "lowest 20%"=5))
#changes x axis variable to continuous

exhibit_5%>%ggplot(aes(axis1, Value))+
geom_line(aes(linetype=TICKER)) +
scale_x_continuous(breaks=c(1,2,3,4,5),
labels=c("highest 20%", "2", "middle 20%", "4", "lowest 20%"))
#changes the x axis tick labels

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

Below is another option. Using a factor variable. datatable3 is the df that has been converted from wide to long.

datatable4<-datatable3%>%
  mutate(axis2=factor(AXISGOLD, levels=c("lowest 20%", "2", "middle 20%", "4", "highest 20%")))
                                         
ggplot(data=datatable4, aes(x=axis2, y=Value, group=GoldType))+
  geom_line(aes(linetype=GoldType))+
  geom_point()

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.